Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make font size dropdown more accessible. #33941

Merged
merged 8 commits into from
Aug 12, 2021
7 changes: 7 additions & 0 deletions packages/components/src/custom-select-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ The label for the control.
- Type: `String`
- Required: Yes

#### describedBy

Pass in a description that will be shown to screen readers associated with the select trigger button. If no value is passed, the text "Currently selected: selectedItem.name" will be used fully translated.

- Type: `String`
- Required: No

#### options

The options that can be chosen from.
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/custom-select-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { Icon, check, chevronDown } from '@wordpress/icons';
import { __, sprintf } from '@wordpress/i18n';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -56,6 +57,7 @@ export default function CustomSelectControl( {
className,
hideLabelFromVision,
label,
describedBy,
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
options: items,
onChange: onSelectedItemChange,
value: _selectedItem,
Expand All @@ -77,6 +79,12 @@ export default function CustomSelectControl( {
stateReducer,
} );

const describedByBuild = describedBy
alexstine marked this conversation as resolved.
Show resolved Hide resolved
? describedBy
: sprintf(
alexstine marked this conversation as resolved.
Show resolved Hide resolved
// translators: %s: The selected option.
__( 'Currently selected: %s' ), selectedItem.name );

const menuProps = getMenuProps( {
className: 'components-custom-select-control__menu',
'aria-hidden': ! isOpen,
Expand Down Expand Up @@ -120,6 +128,7 @@ export default function CustomSelectControl( {
'aria-labelledby': undefined,
className: 'components-custom-select-control__button',
isSmall: true,
describedBy: describedByBuild,
} ) }
>
{ itemToString( selectedItem ) }
Expand Down
9 changes: 8 additions & 1 deletion packages/components/src/font-size-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isNumber, isString } from 'lodash';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { textColor } from '@wordpress/icons';
import { useMemo, forwardRef } from '@wordpress/element';

Expand Down Expand Up @@ -92,6 +92,12 @@ function FontSizePicker(

const selectedFontSizeSlug = getSelectValueFromFontSize( fontSizes, value );

const currentFontSizeSR = sprintf(
// translators: %s: Currently selected font size.
__( 'Currently selected font size: %s' ),
options.find( ( option ) => option.key === selectedFontSizeSlug ).name
);

return (
<fieldset
className="components-font-size-picker"
Expand All @@ -103,6 +109,7 @@ function FontSizePicker(
<CustomSelectControl
className={ 'components-font-size-picker__select' }
label={ __( 'Font size' ) }
describedBy={ currentFontSizeSR }
options={ options }
value={ options.find(
( option ) => option.key === selectedFontSizeSlug
Expand Down