Skip to content

Commit 622fc91

Browse files
fix aria
1 parent 22a2982 commit 622fc91

File tree

7 files changed

+39
-42
lines changed

7 files changed

+39
-42
lines changed

src/plugins/moreButtonPlugin/show-more-tabs/api.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,10 @@ Object.assign(Api.prototype, {
161161
? this.findFirstHiddenTabIndexASC(selectedTabInfo, start, stop)
162162
: this.findFirstHiddenTabIndexDSCE(selectedTabInfo, start, stop);
163163
},
164-
btnContainerPropsGenerator: function (accessibility) {
164+
btnContainerPropsGenerator: function () {
165165
const {tabClass, showMoreContainerClass} = this.api.optionsManager.setting;
166166
const className = tabClass + ' ' + showMoreContainerClass;
167-
let result = {className, ref: this.btnRef};
168-
result =
169-
accessibility == true
170-
? Object.assign(result, {
171-
role: 'button',
172-
'aria-haspopup': 'true',
173-
'aria-label': 'More tabs',
174-
tabindex: -1,
175-
})
176-
: result;
177-
return result;
167+
return {className, ref: this.btnRef};
178168
},
179169
btnPropsGenerator: function (hiddenTabIDs, TabsComponent, accessibility) {
180170
const userButton = this.api.getOption('showMoreButtonComponent');
@@ -188,7 +178,7 @@ Object.assign(Api.prototype, {
188178
this.api.optionsManager.setting;
189179
const result = {
190180
hiddenTabIDs: hiddenTabIDs,
191-
containerButtonRef: this.btnRef, //for assigning aria-expanded
181+
popupContainerID: this._popupContainerID, //todo
192182
instance: this.api.userProxy,
193183
buttonClassName: titleClass + ' ' + showMoreButtonClass,
194184
TabsComponent,
@@ -199,14 +189,13 @@ Object.assign(Api.prototype, {
199189
' ' +
200190
(this.api.getOption('direction') == 'rtl' ? rtlClass + ' ' : '') +
201191
showMorePopperClass,
202-
popupAriaProps: {},
203192
btnAriaProps: {},
204193
};
205194
if (accessibility) {
206-
result.popupAriaProps.role = 'presentation';
207-
result.popupAriaProps.id = this._popupContainerID;
208-
result.btnAriaProps['aria-controls'] = this._popupContainerID;
209-
result.btnAriaProps.tabindex = 0;
195+
result.btnAriaProps.tabIndex = 0;
196+
result.btnAriaProps.role = 'button';
197+
result.btnAriaProps['aria-haspopup'] = 'true';
198+
result.btnAriaProps['aria-label'] = 'More tabs'; //todo
210199
}
211200
return result;
212201
},

src/plugins/moreButtonPlugin/show-more-tabs/button/button.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {useState, useCallback, useRef, useEffect, useLayoutEffect} from 'react';
22
import PropTypes from 'prop-types';
33
export default function Button(getDeps, props) {
4-
const {containerButtonRef} = props;
4+
const {popupContainerID} = props;
55
const {Popper} = getDeps();
66
const [open, setOpen] = useState(false);
77
const btnRef = useRef();
@@ -18,10 +18,16 @@ export default function Button(getDeps, props) {
1818
};
1919
}, []);
2020
useLayoutEffect(() => {
21-
containerButtonRef.current &&
22-
props.instance.getOption('accessibility') &&
23-
containerButtonRef.current.setAttribute('aria-expanded', open ? true : false);
24-
}, [open, containerButtonRef.current]);
21+
if (btnRef.current && props.instance.getOption('accessibility')) {
22+
if (open) {
23+
btnRef.current.setAttribute('aria-expanded', true);
24+
btnRef.current.setAttribute('aria-controls', popupContainerID);
25+
} else {
26+
btnRef.current.setAttribute('aria-expanded', false);
27+
btnRef.current.removeAttribute('aria-controls');
28+
}
29+
}
30+
}, [open, btnRef.current]);
2531
const onClick = useCallback(
2632
(ev) => {
2733
ev.stopPropagation();
@@ -50,7 +56,7 @@ export default function Button(getDeps, props) {
5056
ref={popperRef}
5157
btnRef={btnRef}
5258
className={props.popperClassName}
53-
ariaProps={props.popupAriaProps}
59+
popupContainerID={props.popupContainerID}
5460
/>
5561
) : null}
5662
</>
@@ -62,7 +68,6 @@ Button.propTypes /* remove-proptypes */ = {
6268
instance: PropTypes.object,
6369
hiddenTabIDs: PropTypes.string,
6470
TabsComponent: PropTypes.func,
65-
containerButtonRef: PropTypes.element,
66-
popupAriaProps: PropTypes.object,
71+
popupContainerID: PropTypes.string,
6772
btnAriaProps: PropTypes.object,
6873
};

src/plugins/moreButtonPlugin/show-more-tabs/button/popper/popper.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, {useLayoutEffect} from 'react';
22
import PropTypes from 'prop-types';
33
export default function Popper(getDeps, props, popperRef) {
44
const {createPopper, getPopperMaxHeight, clk} = getDeps();
5-
const {TabsComponent, instance, hiddenTabIDs, btnRef, className, ariaProps} = props;
5+
const {TabsComponent, instance, hiddenTabIDs, btnRef, className, popupContainerID: tablistID} = props;
66
useLayoutEffect(() => {
77
popperRef.current.style.maxHeight = getPopperMaxHeight(btnRef.current, 15) + 'px';
88
const popperIns = createPopper(btnRef.current, popperRef.current);
@@ -14,12 +14,13 @@ export default function Popper(getDeps, props, popperRef) {
1414
const openedTabIDs = hiddenTabIDs ? hiddenTabIDs.split(',') : [];
1515
return (
1616
<>
17-
<div onClick={clk} ref={popperRef} className={className} {...ariaProps}>
17+
<div onClick={clk} ref={popperRef} className={className}>
1818
<TabsComponent
1919
selectedTabID={selectedTabID}
2020
openTabIDs={openedTabIDs}
2121
dir={instance.getOption('direction')}
2222
isVertical={true}
23+
tablistID={tablistID}
2324
/>
2425
</div>
2526
</>
@@ -31,5 +32,5 @@ Popper.propTypes /* remove-proptypes */ = {
3132
instance: PropTypes.object,
3233
btnRef: PropTypes.object,
3334
TabsComponent: PropTypes.func,
34-
ariaProps: PropTypes.object,
35+
popupContainerID: PropTypes.string,
3536
};

src/plugins/moreButtonPlugin/show-more-tabs/show-more-tabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function ShowMoreTabs(getDeps, props) {
3434
? options.showMoreButtonComponent
3535
: Button;
3636
return (
37-
<div {...ins.btnContainerPropsGenerator(options.accessibility)}>
37+
<div {...ins.btnContainerPropsGenerator()}>
3838
<ButtonComponent {...ins.btnPropsGenerator(hiddenTabIDs, TabsComponent, options.accessibility)} />
3939
</div>
4040
);

src/tab/tab.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,46 @@ import memomizeTab from './memomizeTab.js';
33
export const tabPropsManager = function tabPropsManager(ins, props) {
44
const {id, selectedTabID} = props;
55
const isSelected = selectedTabID === id;
6+
const {disable, title, tooltip} = ins.getTab(id);
67
const outputProps = {
78
'tab-id': id,
89
className: ins.getSetting('tabClass'),
910
tabIndex: -1,
11+
title: tooltip || title,
1012
};
1113
//check if tab is selected
1214
if (isSelected) {
1315
outputProps.tabIndex = 0;
1416
outputProps.className += ' ' + ins.getSetting('selectedClass');
1517
}
1618
// check if tab is disable
17-
if (ins.getTab(id).disable) {
19+
if (disable) {
1820
outputProps.tabIndex = -1;
1921
outputProps.className += ' ' + ins.getSetting('disableClass');
2022
}
2123
// check if accessibility option is enable
2224
if (ins.getOption('accessibility')) {
2325
outputProps.role = 'tab';
26+
outputProps.id = ins.getSetting('ariaLabelledbyIdTemplate', id);
2427
outputProps['aria-controls'] = ins.getSetting('panelIdTemplate', id);
25-
outputProps['aria-labelledby'] = ins.getSetting('ariaLabelledbyIdTemplate', id);
28+
outputProps['aria-label'] = tooltip || title;
2629
outputProps['aria-selected'] = outputProps['aria-expanded'] = isSelected;
2730
}
2831
return outputProps;
2932
};
3033
export const tabInnerPropsManager = function tabInnerPropsManager(ins, props) {
3134
const {id, selectedTabID} = props;
3235
const isSelected = selectedTabID == id;
33-
const {tooltip, iconClass} = ins.getTab(id);
36+
const {iconClass} = ins.getTab(id);
3437
const outputProps = {
3538
id,
3639
isSelected,
3740
api: ins.userProxy,
3841
tabProps: {
3942
'tab-id': id,
4043
className: ins.getSetting('titleClass'),
41-
title: tooltip,
4244
tabIndex: -1,
45+
role: 'presentation',
4346
},
4447
};
4548
// check if there is a iconClass option
@@ -49,11 +52,6 @@ export const tabInnerPropsManager = function tabInnerPropsManager(ins, props) {
4952
role: 'presentation',
5053
};
5154
}
52-
// check if accessibility option is enable
53-
if (ins.getOption('accessibility')) {
54-
outputProps.tabProps.id = ins.getSetting('ariaLabelledbyIdTemplate', id);
55-
outputProps.tabProps.role = 'presentation';
56-
}
5755
return outputProps;
5856
};
5957
export const closeIconPropsManager = function closeIconPropsManager(ins) {
@@ -62,7 +60,7 @@ export const closeIconPropsManager = function closeIconPropsManager(ins) {
6260
};
6361
// check if accessibility option is enable
6462
if (ins.getOption('accessibility')) {
65-
outputProps.role = 'presentation';
63+
outputProps.role = 'button';
6664
}
6765
return outputProps;
6866
};

src/tabs/tabs.factory.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import React from 'react';
22
import {ApiContext} from '../context.js';
33
import PropTypes from 'prop-types';
44
function TabsComponent(deps, props, ref) {
5-
const {openTabIDs, selectedTabID, dir, isVertical} = props;
5+
const {openTabIDs, selectedTabID} = props;
66
const {TabsPropsManager, Tab} = deps(React.useContext(ApiContext));
77
return (
8-
<ul {...TabsPropsManager({dir, isVertical})} ref={ref || null}>
8+
<ul {...TabsPropsManager(props)} ref={ref || null}>
99
{openTabIDs.map((id) => (
1010
<Tab key={id} id={id} selectedTabID={selectedTabID}></Tab>
1111
))}
@@ -18,4 +18,5 @@ TabsComponent.propTypes /* remove-proptypes */ = {
1818
dir: PropTypes.string,
1919
isVertical: PropTypes.bool,
2020
openTabIDs: PropTypes.array,
21+
tablistID: PropTypes.string,
2122
};

src/tabs/tabs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export const TabsPropsManager = function (ins, props) {
1212
if (ins.getOption('accessibility')) {
1313
result.role = 'tablist';
1414
}
15+
if (props.tablistID) {
16+
result.id = props.tablistID;
17+
}
1518
return result;
1619
};
1720
export default forwardRef(

0 commit comments

Comments
 (0)