Skip to content

Commit

Permalink
Fix #3292: ARIA expand and collapse labels (#3293)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Sep 12, 2022
1 parent 1abfdce commit 4fd69a1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 27 deletions.
4 changes: 3 additions & 1 deletion components/lib/accordion/Accordion.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { ariaLabel } from '../api/Api';
import { CSSTransition } from '../csstransition/CSSTransition';
import { useMountEffect } from '../hooks/Hooks';
import { classNames, IconUtils, ObjectUtils, UniqueComponentId } from '../utils/Utils';
Expand Down Expand Up @@ -76,10 +77,11 @@ export const Accordion = React.forwardRef((props, ref) => {
const tabIndex = tab.props.disabled ? -1 : null;
const header = tab.props.headerTemplate ? ObjectUtils.getJSXElement(tab.props.headerTemplate, tab.props) : <span className="p-accordion-header-text">{tab.props.header}</span>;
const icon = IconUtils.getJSXIcon(selected ? props.collapseIcon : props.expandIcon, { className: 'p-accordion-toggle-icon' }, { props, selected });
const label = selected ? ariaLabel('collapseLabel') : ariaLabel('expandLabel');

return (
<div className={className} style={style}>
<a href={'#' + ariaControls} id={headerId} className="p-accordion-header-link" aria-controls={ariaControls} role="tab" aria-expanded={selected} onClick={(e) => onTabHeaderClick(e, tab, index)} tabIndex={tabIndex}>
<a href={'#' + ariaControls} id={headerId} className="p-accordion-header-link" aria-controls={ariaControls} role="tab" aria-expanded={selected} onClick={(e) => onTabHeaderClick(e, tab, index)} tabIndex={tabIndex} aria-label={label}>
{icon}
{header}
</a>
Expand Down
4 changes: 3 additions & 1 deletion components/lib/api/Locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ let locales = {
nextPageLabel: 'Next Page',
previousPageLabel: 'Previous Page',
selectLabel: 'Select',
unselectLabel: 'Unselect'
unselectLabel: 'Unselect',
expandLabel: 'Expand',
collapseLabel: 'Collapse'
}
}
};
Expand Down
9 changes: 5 additions & 4 deletions components/lib/datatable/BodyCell.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { ariaLabel } from '../api/Api';
import { Button } from '../button/Button';
import { useEventListener, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks';
import { OverlayService } from '../overlayservice/OverlayService';
import { Ripple } from '../ripple/Ripple';
Expand Down Expand Up @@ -524,17 +525,17 @@ export const BodyCell = React.memo((props) => {
} else if (expander) {
const iconClassName = classNames('p-row-toggler-icon', props.expanded ? props.expandedRowIcon : props.collapsedRowIcon);
const ariaControls = `${props.tableSelector}_content_${props.rowIndex}_expanded`;
const ariaLabelField = props.selectionAriaLabel || props.tableProps.dataKey;
const ariaLabelText = ObjectUtils.resolveFieldData(props.rowData, ariaLabelField);
const label = `${props.expanded ? ariaLabel('collapseLabel') : ariaLabel('expandLabel')} ${ariaLabelText}`;
const expanderProps = {
onClick: onRowToggle,
className: 'p-row-toggler p-link',
iconClassName
};

content = (
<button className={expanderProps.className} onClick={expanderProps.onClick} type="button" aria-expanded={props.expanded} aria-controls={ariaControls} tabIndex={props.tabIndex}>
<span className={expanderProps.iconClassName}></span>
<Ripple />
</button>
<Button className={expanderProps.className} onClick={expanderProps.onClick} type="button" icon={expanderProps.iconClassName} aria-expanded={props.expanded} aria-controls={ariaControls} tabIndex={props.tabIndex} ariaLabel={label} />
);

if (body) {
Expand Down
11 changes: 4 additions & 7 deletions components/lib/datatable/RowTogglerButton.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { Ripple } from '../ripple/Ripple';
import { ariaLabel } from '../api/Api';
import { Button } from '../button/Button';
import { classNames } from '../utils/Utils';

export const RowTogglerButton = React.memo((props) => {
Expand All @@ -11,13 +12,9 @@ export const RowTogglerButton = React.memo((props) => {
};

const iconClassName = classNames('p-row-toggler-icon', props.expanded ? props.expandedRowIcon : props.collapsedRowIcon);
const label = props.expanded ? ariaLabel('collapseLabel') : ariaLabel('expandLabel');

return (
<button type="button" onClick={onClick} className="p-row-toggler p-link" tabIndex={props.tabIndex}>
<span className={iconClassName}></span>
<Ripple />
</button>
);
return <Button className="p-row-toggler p-link" onClick={onClick} type="button" icon={iconClassName} tabIndex={props.tabIndex} ariaLabel={label} />;
});

RowTogglerButton.displayName = 'RowTogglerButton';
11 changes: 4 additions & 7 deletions components/lib/tree/UITreeNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { Ripple } from '../ripple/Ripple';
import { ariaLabel } from '../api/Api';
import { Button } from '../button/Button';
import { classNames, DomHandler, ObjectUtils } from '../utils/Utils';

export const UITreeNode = React.memo((props) => {
Expand Down Expand Up @@ -561,13 +562,9 @@ export const UITreeNode = React.memo((props) => {
};

const createToggler = () => {
const label = expanded ? ariaLabel('collapseLabel') : ariaLabel('expandLabel');
const iconClassName = classNames('p-tree-toggler-icon pi pi-fw', { 'pi-chevron-right': !expanded, 'pi-chevron-down': expanded });
let content = (
<button type="button" className="p-tree-toggler p-link" tabIndex={-1} onClick={onTogglerClick}>
<span className={iconClassName}></span>
<Ripple />
</button>
);
let content = <Button type="button" className="p-tree-toggler p-link" tabIndex={-1} onClick={onTogglerClick} icon={iconClassName} ariaLabel={label} />;

if (props.togglerTemplate) {
const defaultContentOptions = {
Expand Down
11 changes: 4 additions & 7 deletions components/lib/treetable/TreeTableRow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { Ripple } from '../ripple/Ripple';
import { ariaLabel } from '../api/Api';
import { Button } from '../button/Button';
import { classNames, DomHandler } from '../utils/Utils';
import { TreeTableBodyCell } from './TreeTableBodyCell';

Expand Down Expand Up @@ -263,15 +264,11 @@ export const TreeTableRow = React.memo((props) => {
};

const createToggler = () => {
const label = expanded ? ariaLabel('collapseLabel') : ariaLabel('expandLabel');
const iconClassName = classNames('p-treetable-toggler-icon pi pi-fw', { 'pi-chevron-right': !expanded, 'pi-chevron-down': expanded });
const style = { marginLeft: props.level * 16 + 'px', visibility: props.node.leaf === false || (props.node.children && props.node.children.length) ? 'visible' : 'hidden' };

return (
<button type="button" className="p-treetable-toggler p-link p-unselectable-text" onClick={onTogglerClick} tabIndex={-1} style={style}>
<i className={iconClassName}></i>
<Ripple />
</button>
);
return <Button type="button" className="p-treetable-toggler p-link p-unselectable-text" style={style} tabIndex={-1} onClick={onTogglerClick} icon={iconClassName} ariaLabel={label} />;
};

const createCheckbox = () => {
Expand Down
8 changes: 8 additions & 0 deletions pages/locale/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ locale('es');
<td>aria.unselectLabel</td>
<td>Unselect</td>
</tr>
<tr>
<td>aria.expandLabel</td>
<td>Expand</td>
</tr>
<tr>
<td>aria.collapseLabel</td>
<td>Collapse</td>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit 4fd69a1

Please sign in to comment.