Skip to content

Commit 322231b

Browse files
authored
feat(thumbnail-card): remove role and tabIndex when onKeyDown exists (#3898)
* feat(thumbnail-card): remove role and tabIndex when onKeyDown * feat(thumbnail-card): update spec
1 parent 4e0712b commit 322231b

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/components/thumbnail-card/ThumbnailCard.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const ThumbnailCard = ({
3030
...rest
3131
}: Props) => (
3232
<div
33-
role="button"
34-
tabIndex="0"
3533
className={classNames('thumbnail-card', className, { 'is-highlight-applied': highlightOnHover })}
34+
role={onKeyDown ? null : 'button'}
35+
tabIndex={onKeyDown ? null : 0}
3636
{...rest}
3737
>
3838
<ThumbnailCardThumbnail thumbnail={thumbnail} />

src/components/thumbnail-card/__tests__/ThumbnailCard.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ describe('components/thumbnail-card/ThumbnailCard', () => {
2020
expect(wrapper).toMatchSnapshot();
2121
});
2222

23+
test('should have role and tabIndex when onKeyDown prop does not exist', () => {
24+
const wrapper = getWrapper();
25+
26+
expect(wrapper.find('.thumbnail-card').prop('role')).toBe('button');
27+
expect(wrapper.find('.thumbnail-card').prop('tabIndex')).toBe(0);
28+
});
29+
30+
test('should not have role and tabIndex when onKeyDown prop exists', () => {
31+
const onKeyDown = () => {};
32+
const wrapper = getWrapper({ onKeyDown });
33+
34+
expect(wrapper.find('.thumbnail-card').prop('role')).toBe(null);
35+
expect(wrapper.find('.thumbnail-card').prop('tabIndex')).toBe(null);
36+
});
37+
2338
test('should pass down actionItem, icon, and subtitle', () => {
2439
const icon = <img alt="icon" />;
2540
const subtitle = <div>Subtitle!</div>;

src/components/thumbnail-card/__tests__/__snapshots__/ThumbnailCard.test.js.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`components/thumbnail-card/ThumbnailCard should pass down actionItem, ic
44
<div
55
className="thumbnail-card"
66
role="button"
7-
tabIndex="0"
7+
tabIndex={0}
88
>
99
<ThumbnailCardThumbnail
1010
thumbnail={
@@ -44,7 +44,7 @@ exports[`components/thumbnail-card/ThumbnailCard should render 1`] = `
4444
<div
4545
className="thumbnail-card"
4646
role="button"
47-
tabIndex="0"
47+
tabIndex={0}
4848
>
4949
<ThumbnailCardThumbnail
5050
thumbnail={
@@ -67,7 +67,7 @@ exports[`components/thumbnail-card/ThumbnailCard should use additional className
6767
<div
6868
className="thumbnail-card fooBar"
6969
role="button"
70-
tabIndex="0"
70+
tabIndex={0}
7171
>
7272
<ThumbnailCardThumbnail
7373
thumbnail={

0 commit comments

Comments
 (0)