Skip to content

Commit 0fcefef

Browse files
committed
Remove warning from Gallery component.
Decision was made to remove the check on children since there isn’t really a strong reason. It’s the responsibility of the caller to make sure they pass the right attributes. Also remove the automatic generation of the alt attribute since it doesn’t make sense in most contexts. https://glints.atlassian.net/browse/SS-777
1 parent 92582a5 commit 0fcefef

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

src/Display/Gallery/Gallery.test.tsx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ const Component = ({
1717
initialVisibility={initialVisibility}
1818
imagesDisplayed={imagesDisplayed}
1919
>
20-
<img src="1" />
21-
<img src="2" />
22-
<img src="3" />
23-
<img src="4" />
24-
<img src="5" />
25-
<img src="6" />
26-
<img src="7" />
27-
<img src="8" />
28-
<img src="9" />
29-
<img src="10" />
20+
<img src="1" alt="0" />
21+
<img src="2" alt="1" />
22+
<img src="3" alt="2" />
23+
<img src="4" alt="3" />
24+
<img src="5" alt="4" />
25+
<img src="6" alt="5" />
26+
<img src="7" alt="6" />
27+
<img src="8" alt="7" />
28+
<img src="9" alt="8" />
29+
<img src="10" alt="9" />
3030
</Gallery>
3131
);
3232

@@ -74,14 +74,6 @@ describe('<Gallery /> rendering', () => {
7474
);
7575
expect(asFragment()).toMatchSnapshot();
7676
});
77-
78-
it('should return console error when item is invalid children', () => {
79-
const error = jest.spyOn(console, 'error').mockImplementation();
80-
render(<GalleryItemWithInvalidChildren />);
81-
82-
expect(error).toBeCalledWith('Only img components allowed as children.');
83-
error.mockRestore();
84-
});
8577
});
8678

8779
describe('<Gallery /> open and close Slider modal', () => {

src/Display/Gallery/Gallery.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ const Gallery = ({
3535

3636
const getCurrentIndex = (index: number) => setCurrentIndex(index - 1);
3737

38-
const hasImage = React.Children.toArray(children).some(child => {
39-
return React.isValidElement(child) && child.type === 'img';
40-
});
41-
if (!hasImage) {
42-
console.error('Only img components allowed as children.');
43-
}
44-
4538
React.useEffect(function componentDidMount() {
4639
if (React.Children.count(children) > imagesDisplayed)
4740
setImageLeft(React.Children.count(children) - imagesDisplayed);
@@ -93,9 +86,7 @@ const Gallery = ({
9386
(data: React.ReactElement<React.HTMLProps<'img'>>, index) => (
9487
<Slider.Item key={`${data.props.src}_${index}`}>
9588
<GalleryImageWrapper role="banner" tabIndex={0}>
96-
{React.cloneElement(data, {
97-
alt: index.toString(10),
98-
})}
89+
{data}
9990
</GalleryImageWrapper>
10091
</Slider.Item>
10192
)
@@ -117,7 +108,6 @@ const Gallery = ({
117108
{React.cloneElement(data, {
118109
className: index === currentIndex ? 'active' : null,
119110
'data-testid': 'gallery_thumbnail',
120-
alt: index.toString(10),
121111
})}
122112
</div>
123113
)

0 commit comments

Comments
 (0)