From a729c5974b2dd57ad142dd9f71b1ce1532442d1a Mon Sep 17 00:00:00 2001 From: melloware Date: Mon, 12 Sep 2022 10:28:53 -0400 Subject: [PATCH] Fix #3292: ARIA expand and collapse labels --- components/lib/accordion/Accordion.js | 4 +++- components/lib/api/Locale.js | 4 +++- components/lib/datatable/BodyCell.js | 9 +++++---- components/lib/datatable/RowTogglerButton.js | 11 ++++------- components/lib/tree/UITreeNode.js | 11 ++++------- components/lib/treetable/TreeTableRow.js | 11 ++++------- pages/locale/index.js | 8 ++++++++ 7 files changed, 31 insertions(+), 27 deletions(-) diff --git a/components/lib/accordion/Accordion.js b/components/lib/accordion/Accordion.js index 7483a7ad79..8daf240409 100644 --- a/components/lib/accordion/Accordion.js +++ b/components/lib/accordion/Accordion.js @@ -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'; @@ -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) : {tab.props.header}; const icon = IconUtils.getJSXIcon(selected ? props.collapseIcon : props.expandIcon, { className: 'p-accordion-toggle-icon' }, { props, selected }); + const label = selected ? ariaLabel('collapseLabel') : ariaLabel('expandLabel'); return (
- onTabHeaderClick(e, tab, index)} tabIndex={tabIndex}> + onTabHeaderClick(e, tab, index)} tabIndex={tabIndex} aria-label={label}> {icon} {header} diff --git a/components/lib/api/Locale.js b/components/lib/api/Locale.js index 978621867c..9ef62f652d 100644 --- a/components/lib/api/Locale.js +++ b/components/lib/api/Locale.js @@ -56,7 +56,9 @@ let locales = { nextPageLabel: 'Next Page', previousPageLabel: 'Previous Page', selectLabel: 'Select', - unselectLabel: 'Unselect' + unselectLabel: 'Unselect', + expandLabel: 'Expand', + collapseLabel: 'Collapse' } } }; diff --git a/components/lib/datatable/BodyCell.js b/components/lib/datatable/BodyCell.js index d29a3d969b..96b8582920 100644 --- a/components/lib/datatable/BodyCell.js +++ b/components/lib/datatable/BodyCell.js @@ -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'; @@ -524,6 +525,9 @@ 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', @@ -531,10 +535,7 @@ export const BodyCell = React.memo((props) => { }; content = ( - + - ); + return - ); + let content = - ); + return