Skip to content

Commit 5529d17

Browse files
BennyHudsonBen Hudson
and
Ben Hudson
authored
Updating roles & tabindexes based on #403 (#469)
Co-authored-by: Ben Hudson <[email protected]>
1 parent 0d8799c commit 5529d17

File tree

4 files changed

+10
-62
lines changed

4 files changed

+10
-62
lines changed

src/Slide/Slide.jsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const Slide = class Slide extends React.PureComponent {
2121
onFocus: PropTypes.func,
2222
orientation: CarouselPropTypes.orientation.isRequired,
2323
slideSize: PropTypes.number.isRequired,
24+
role: PropTypes.string,
2425
style: PropTypes.object,
25-
tabIndex: PropTypes.number,
2626
tag: PropTypes.string,
2727
totalSlides: PropTypes.number.isRequired,
2828
visibleSlides: PropTypes.number.isRequired,
@@ -40,8 +40,8 @@ const Slide = class Slide extends React.PureComponent {
4040
innerTag: 'div',
4141
onBlur: null,
4242
onFocus: null,
43+
role: 'option',
4344
style: {},
44-
tabIndex: null,
4545
tag: 'div',
4646
isIntrinsicHeight: false,
4747
}
@@ -104,7 +104,6 @@ const Slide = class Slide extends React.PureComponent {
104104
orientation,
105105
slideSize,
106106
style,
107-
tabIndex,
108107
tag: Tag,
109108
totalSlides,
110109
visibleSlides,
@@ -155,16 +154,12 @@ const Slide = class Slide extends React.PureComponent {
155154
innerClassName,
156155
]);
157156

158-
const defaultTabIndex = this.isVisible() ? 0 : -1;
159-
const newTabIndex = typeof tabIndex === 'number' ? tabIndex : defaultTabIndex;
160-
161157
return (
162158
<Tag
163159
ref={(el) => { this.tagRef = el; }}
164-
tabIndex={newTabIndex}
165160
aria-selected={this.isVisible()}
166161
aria-label={ariaLabel}
167-
role="option"
162+
role={this.props.role}
168163
onFocus={this.handleOnFocus}
169164
onBlur={this.handleOnBlur}
170165
className={newClassName}

src/Slide/__tests__/Slide.test.jsx

+3-38
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,7 @@ describe('<Slide />', () => {
5858
const wrapper = shallow(<Slide {...props} orientation="vertical" />);
5959
expect(wrapper.find('.slide').prop('style').width).toBe('100%');
6060
});
61-
it('should have a tabIndex of -1 if the slide is not visible within the slideTray (index < currentSlide)', () => {
62-
const wrapper = shallow((
63-
<Slide
64-
currentSlide={1}
65-
index={0}
66-
naturalSlideHeight={400}
67-
naturalSlideWidth={300}
68-
orientation="horizontal"
69-
slideSize={25}
70-
totalSlides={6}
71-
visibleSlides={2}
72-
/>
73-
));
74-
expect(wrapper.find('.slide').prop('tabIndex')).toBe(-1);
75-
});
61+
7662
it('should apply any supplied classes to hidden slides', () => {
7763
const wrapper = shallow((
7864
<Slide
@@ -109,30 +95,10 @@ describe('<Slide />', () => {
10995
expect(wrapper.find('.slide').hasClass('i-be-visible')).toBe(true);
11096
expect(wrapper.find('.slide').hasClass('carousel__slide--visible')).toBe(true);
11197
});
112-
it('should have a tabIndex of -1 if the slide is not visible within the slideTray (index >= currentSlide + visibleSlides)', () => {
113-
const wrapper = shallow((
114-
<Slide
115-
currentSlide={1}
116-
index={3}
117-
naturalSlideHeight={400}
118-
naturalSlideWidth={300}
119-
orientation="horizontal"
120-
slideSize={25}
121-
totalSlides={6}
122-
visibleSlides={2}
123-
/>
124-
));
125-
expect(wrapper.find('.slide').prop('tabIndex')).toBe(-1);
126-
});
127-
it('if a tabIndex prop is supplied, set the tabIndex to that value and ignore our internally computed value.', () => {
128-
// this is for testing only.
129-
// eslint-disable-next-line jsx-a11y/tabindex-no-positive
130-
const wrapper = shallow(<Slide {...props} tabIndex={7} />);
131-
expect(wrapper.find('.slide').prop('tabIndex')).toBe(7);
132-
});
98+
13399
it('should correctly set styles, if isIntrinsicHeight is set', () => {
134100
// this is for testing only.
135-
// eslint-disable-next-line jsx-a11y/tabindex-no-positive
101+
136102
const wrapper = shallow(<Slide {...props} isIntrinsicHeight />);
137103
const slideStyle = wrapper.find('.slide').prop('style');
138104
expect(slideStyle.paddingBottom).toBe('unset');
@@ -143,7 +109,6 @@ describe('<Slide />', () => {
143109
});
144110
it('should correctly set styles, in vertical mode if isIntrinsicHeight is set', () => {
145111
// this is for testing only.
146-
// eslint-disable-next-line jsx-a11y/tabindex-no-positive
147112
const wrapper = shallow(<Slide {...props} orientation="vertical" isIntrinsicHeight />);
148113
const slideStyle = wrapper.find('.slide').prop('style');
149114
expect(slideStyle.paddingBottom).toBe('unset');

src/Slider/Slider.jsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ const Slider = class Slider extends React.Component {
3838
orientation: CarouselPropTypes.orientation.isRequired,
3939
playDirection: CarouselPropTypes.direction.isRequired,
4040
privateUnDisableAnimation: PropTypes.bool,
41+
role: PropTypes.string,
4142
slideSize: PropTypes.number.isRequired,
4243
slideTraySize: PropTypes.number.isRequired,
4344
spinner: PropTypes.func,
4445
step: PropTypes.number.isRequired,
4546
style: PropTypes.object,
46-
tabIndex: PropTypes.number,
4747
totalSlides: PropTypes.number.isRequired,
4848
touchEnabled: PropTypes.bool.isRequired,
4949
trayProps: PropTypes.shape({
@@ -78,9 +78,9 @@ const Slider = class Slider extends React.Component {
7878
moveThreshold: 0.1,
7979
onMasterSpinner: null,
8080
privateUnDisableAnimation: false,
81+
role: 'listbox',
8182
spinner: null,
8283
style: {},
83-
tabIndex: null,
8484
trayProps: {},
8585
trayTag: 'div',
8686
visibleSlides: 1,
@@ -582,7 +582,6 @@ const Slider = class Slider extends React.Component {
582582
slideTraySize,
583583
spinner,
584584
style,
585-
tabIndex,
586585
totalSlides,
587586
touchEnabled,
588587
trayProps,
@@ -654,7 +653,7 @@ const Slider = class Slider extends React.Component {
654653
classNameTray,
655654
]);
656655

657-
const newTabIndex = tabIndex !== null ? tabIndex : 0;
656+
658657

659658
// remove invalid div attributes
660659
const {
@@ -691,10 +690,9 @@ const Slider = class Slider extends React.Component {
691690
className={sliderClasses}
692691
aria-live="polite"
693692
aria-label={ariaLabel}
693+
role={this.props.role}
694694
style={sliderStyle}
695-
tabIndex={newTabIndex}
696695
onKeyDown={this.handleOnKeyDown}
697-
role="listbox"
698696
{...rest}
699697
>
700698
<div className={trayWrapClasses} style={trayWrapStyle}>

src/Slider/__tests__/Slider.test.jsx

-10
Original file line numberDiff line numberDiff line change
@@ -935,16 +935,6 @@ describe('<Slider />', () => {
935935
expect(wrapper.prop('carouselStore').state.currentSlide).toBe(1);
936936
});
937937

938-
it('the .carousel__slider should have a default tabIndex of 0', () => {
939-
const wrapper = shallow(<Slider {...props} />);
940-
expect(wrapper.find('.carousel__slider').prop('tabIndex')).toBe(0);
941-
});
942-
943-
it('override the default tabIndex for .carousel__slider if a tabIndex prop is passed to this component', () => {
944-
const wrapper = shallow(<Slider {...props} tabIndex={-1} />);
945-
expect(wrapper.find('.carousel__slider').prop('tabIndex')).toBe(-1);
946-
});
947-
948938
it('should not call this.focus() if totalSlides <= visibleSlides', () => {
949939
const wrapper = shallow(<Slider {...props} totalSlides={2} visibleSlides={2} />);
950940
const instance = wrapper.instance();

0 commit comments

Comments
 (0)