From 58c1a1ecc62c4b144576179f26cc1a3bd63c8187 Mon Sep 17 00:00:00 2001 From: Melloware Date: Wed, 14 Sep 2022 17:46:39 -0400 Subject: [PATCH] Fix #839/#1852/#3319: ARIA support to input elements (#3323) --- components/lib/autocomplete/AutoComplete.js | 11 ++--- components/lib/cascadeselect/CascadeSelect.js | 6 ++- components/lib/checkbox/Checkbox.js | 8 ++-- components/lib/chips/Chips.js | 3 +- components/lib/dropdown/Dropdown.js | 9 ++-- components/lib/inputnumber/InputNumber.js | 5 +- components/lib/inputswitch/InputSwitch.js | 8 ++-- components/lib/listbox/ListBox.js | 9 ++-- components/lib/mention/Mention.js | 48 +++++++------------ components/lib/multiselect/MultiSelect.js | 5 +- .../multistatecheckbox/MultiStateCheckbox.js | 20 ++------ components/lib/radiobutton/RadioButton.js | 8 ++-- components/lib/slider/Slider.js | 8 ++-- components/lib/tree/Tree.js | 5 +- components/lib/treeselect/TreeSelect.js | 4 +- .../lib/tristatecheckbox/TriStateCheckbox.js | 19 ++------ components/lib/utils/DomHandler.js | 9 ++++ components/lib/utils/ObjectUtils.js | 8 ++-- 18 files changed, 78 insertions(+), 115 deletions(-) diff --git a/components/lib/autocomplete/AutoComplete.js b/components/lib/autocomplete/AutoComplete.js index c316170b0d..4011f6debe 100644 --- a/components/lib/autocomplete/AutoComplete.js +++ b/components/lib/autocomplete/AutoComplete.js @@ -492,8 +492,6 @@ export const AutoComplete = React.memo( aria-controls={ariaControls} aria-haspopup="listbox" aria-expanded={overlayVisibleState} - aria-labelledby={props['aria-labelledby']} - aria-label={props['aria-label']} className={className} style={props.inputStyle} autoComplete="off" @@ -513,6 +511,7 @@ export const AutoComplete = React.memo( onContextMenu={props.onContextMenu} onClick={props.onClick} onDoubleClick={props.onDblClick} + {...ariaProps} {...dataProps} /> ); @@ -550,8 +549,6 @@ export const AutoComplete = React.memo( aria-controls={ariaControls} aria-haspopup="listbox" aria-expanded={overlayVisibleState} - aria-labelledby={props['aria-labelledby']} - aria-label={props['aria-label']} autoComplete="off" tabIndex={props.tabIndex} onChange={onInputChange} @@ -565,6 +562,7 @@ export const AutoComplete = React.memo( onKeyPress={props.onKeyPress} onFocus={onMultiInputFocus} onBlur={onMultiInputBlur} + {...ariaProps} {...dataProps} /> @@ -611,7 +609,8 @@ export const AutoComplete = React.memo( const listId = idState + '_list'; const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const otherProps = ObjectUtils.findDiffKeys(props, AutoComplete.defaultProps); - const dataProps = ObjectUtils.reduceKeys(otherProps, 'data'); + const dataProps = ObjectUtils.reduceKeys(otherProps, DomHandler.DATA_PROPS); + const ariaProps = ObjectUtils.reduceKeys(otherProps, DomHandler.ARIA_PROPS); const className = classNames( 'p-autocomplete p-component p-inputwrapper', { @@ -660,8 +659,6 @@ AutoComplete.displayName = 'AutoComplete'; AutoComplete.defaultProps = { __TYPE: 'AutoComplete', id: null, - 'aria-label': null, - 'aria-labelledby': null, appendTo: null, autoFocus: false, autoHighlight: false, diff --git a/components/lib/cascadeselect/CascadeSelect.js b/components/lib/cascadeselect/CascadeSelect.js index 60834d0bd5..9a6d3d0d48 100644 --- a/components/lib/cascadeselect/CascadeSelect.js +++ b/components/lib/cascadeselect/CascadeSelect.js @@ -229,7 +229,7 @@ export const CascadeSelect = React.memo( onKeyDown={onInputKeyDown} tabIndex={props.tabIndex} aria-haspopup="listbox" - aria-labelledby={props.ariaLabelledBy} + {...ariaProps} /> ); @@ -299,7 +299,6 @@ export const CascadeSelect = React.memo( }; const createElement = () => { - const otherProps = ObjectUtils.findDiffKeys(props, CascadeSelect.defaultProps); const className = classNames( 'p-cascadeselect p-component p-inputwrapper', { @@ -326,6 +325,9 @@ export const CascadeSelect = React.memo( ); }; + const otherProps = ObjectUtils.findDiffKeys(props, CascadeSelect.defaultProps); + const dataProps = ObjectUtils.reduceKeys(otherProps, DomHandler.DATA_PROPS); + const ariaProps = ObjectUtils.reduceKeys(otherProps, DomHandler.ARIA_PROPS); const element = createElement(); return element; diff --git a/components/lib/checkbox/Checkbox.js b/components/lib/checkbox/Checkbox.js index ee49f5780c..9fc3e73794 100644 --- a/components/lib/checkbox/Checkbox.js +++ b/components/lib/checkbox/Checkbox.js @@ -75,7 +75,8 @@ export const Checkbox = React.memo( const checked = isChecked(); const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const otherProps = ObjectUtils.findDiffKeys(props, Checkbox.defaultProps); - const dataProps = ObjectUtils.reduceKeys(otherProps, 'data'); + const dataProps = ObjectUtils.reduceKeys(otherProps, DomHandler.DATA_PROPS); + const ariaProps = ObjectUtils.reduceKeys(otherProps, DomHandler.ARIA_PROPS); const className = classNames( 'p-checkbox p-component', { @@ -103,14 +104,13 @@ export const Checkbox = React.memo( name={props.name} tabIndex={props.tabIndex} defaultChecked={checked} - aria-labelledby={props['aria-labelledby']} - aria-label={props['aria-label']} onFocus={onFocus} onBlur={onBlur} onKeyDown={onKeyDown} disabled={props.disabled} readOnly={props.readOnly} required={props.required} + {...ariaProps} {...dataProps} /> @@ -142,8 +142,6 @@ Checkbox.defaultProps = { icon: 'pi pi-check', tooltip: null, tooltipOptions: null, - 'aria-label': null, - 'aria-labelledby': null, onChange: null, onMouseDown: null, onContextMenu: null diff --git a/components/lib/chips/Chips.js b/components/lib/chips/Chips.js index a37245d539..edb6b0b6b0 100644 --- a/components/lib/chips/Chips.js +++ b/components/lib/chips/Chips.js @@ -228,8 +228,8 @@ export const Chips = React.memo( onPaste={onPaste} onFocus={onFocus} onBlur={onBlur} - aria-labelledby={props.ariaLabelledBy} readOnly={props.readOnly} + {...ariaProps} /> ); @@ -257,6 +257,7 @@ export const Chips = React.memo( const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const otherProps = ObjectUtils.findDiffKeys(props, Chips.defaultProps); + const ariaProps = ObjectUtils.reduceKeys(otherProps, DomHandler.ARIA_PROPS); const className = classNames( 'p-chips p-component p-inputwrapper', { diff --git a/components/lib/dropdown/Dropdown.js b/components/lib/dropdown/Dropdown.js index 43d639d4dc..52d41229f8 100644 --- a/components/lib/dropdown/Dropdown.js +++ b/components/lib/dropdown/Dropdown.js @@ -661,8 +661,7 @@ export const Dropdown = React.memo( onKeyDown={onInputKeyDown} disabled={props.disabled} tabIndex={props.tabIndex} - aria-label={props.ariaLabel} - aria-labelledby={props.ariaLabelledBy} + {...ariaProps} /> ); @@ -686,9 +685,8 @@ export const Dropdown = React.memo( onInput={onEditableInputChange} onFocus={onEditableInputFocus} onBlur={onInputBlur} - aria-label={props.ariaLabel} - aria-labelledby={props.ariaLabelledBy} aria-haspopup="listbox" + {...ariaProps} /> ); } else { @@ -730,7 +728,8 @@ export const Dropdown = React.memo( const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const otherProps = ObjectUtils.findDiffKeys(props, Dropdown.defaultProps); - const dataProps = ObjectUtils.reduceKeys(otherProps, 'data'); + const dataProps = ObjectUtils.reduceKeys(otherProps, DomHandler.DATA_PROPS); + const ariaProps = ObjectUtils.reduceKeys(otherProps, DomHandler.ARIA_PROPS); const className = classNames( 'p-dropdown p-component p-inputwrapper', { diff --git a/components/lib/inputnumber/InputNumber.js b/components/lib/inputnumber/InputNumber.js index 85bda359b9..8a4e3f8217 100644 --- a/components/lib/inputnumber/InputNumber.js +++ b/components/lib/inputnumber/InputNumber.js @@ -1017,7 +1017,7 @@ export const InputNumber = React.memo( aria-valuemin={props.min} aria-valuemax={props.max} aria-valuenow={props.value} - aria-labelledby={props.ariaLabelledBy} + {...ariaProps} {...dataProps} /> ); @@ -1106,7 +1106,8 @@ export const InputNumber = React.memo( const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const otherProps = ObjectUtils.findDiffKeys(props, InputNumber.defaultProps); - const dataProps = ObjectUtils.reduceKeys(otherProps, 'data'); + const dataProps = ObjectUtils.reduceKeys(otherProps, DomHandler.DATA_PROPS); + const ariaProps = ObjectUtils.reduceKeys(otherProps, DomHandler.ARIA_PROPS); const className = classNames( 'p-inputnumber p-component p-inputwrapper', { diff --git a/components/lib/inputswitch/InputSwitch.js b/components/lib/inputswitch/InputSwitch.js index 264b169fcf..6525d6d73e 100644 --- a/components/lib/inputswitch/InputSwitch.js +++ b/components/lib/inputswitch/InputSwitch.js @@ -60,7 +60,8 @@ export const InputSwitch = React.memo( const hasTooltip = ObjectUtils.isNotEmpty(props.tooltip); const otherProps = ObjectUtils.findDiffKeys(props, InputSwitch.defaultProps); - const dataProps = ObjectUtils.reduceKeys(otherProps, 'data'); + const dataProps = ObjectUtils.reduceKeys(otherProps, DomHandler.DATA_PROPS); + const ariaProps = ObjectUtils.reduceKeys(otherProps, DomHandler.ARIA_PROPS); const className = classNames( 'p-inputswitch p-component', { @@ -88,8 +89,7 @@ export const InputSwitch = React.memo( role="switch" tabIndex={props.tabIndex} aria-checked={checked} - aria-labelledby={props['aria-labelledby']} - aria-label={props['aria-label']} + {...ariaProps} {...dataProps} /> @@ -104,8 +104,6 @@ export const InputSwitch = React.memo( InputSwitch.displayName = 'InputSwitch'; InputSwitch.defaultProps = { __TYPE: 'InputSwitch', - 'aria-label': null, - 'aria-labelledby': null, checked: false, className: null, disabled: false, diff --git a/components/lib/listbox/ListBox.js b/components/lib/listbox/ListBox.js index ddef92a2df..6b5d057bf5 100644 --- a/components/lib/listbox/ListBox.js +++ b/components/lib/listbox/ListBox.js @@ -2,7 +2,7 @@ import * as React from 'react'; import { FilterService } from '../api/Api'; import { useMountEffect } from '../hooks/Hooks'; import { Tooltip } from '../tooltip/Tooltip'; -import { classNames, ObjectUtils } from '../utils/Utils'; +import { classNames, DomHandler, ObjectUtils } from '../utils/Utils'; import { VirtualScroller } from '../virtualscroller/VirtualScroller'; import { ListBoxHeader } from './ListBoxHeader'; import { ListBoxItem } from './ListBoxItem'; @@ -358,7 +358,7 @@ export const ListBox = React.memo( const className = classNames('p-listbox-list', option.className); return ( -