Skip to content

Commit

Permalink
Add id for slider aria labels
Browse files Browse the repository at this point in the history
  • Loading branch information
brookewp committed Dec 12, 2023
1 parent eb8ebe8 commit 3192ad7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/components/src/box-control/all-input-control.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* WordPress dependencies
*/
import { useInstanceId } from '@wordpress/compose';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -29,6 +33,7 @@ export default function AllInputControl( {
setSelectedUnits,
...props
}: BoxControlInputControlProps ) {
const inputId = useInstanceId( AllInputControl, 'box-control-input' );
const allValue = getAllValue( values, selectedUnits, sides );
const hasValues = isValuesDefined( values );
const isMixed = hasValues && isValuesMixed( values, selectedUnits, sides );
Expand Down Expand Up @@ -86,6 +91,7 @@ export default function AllInputControl( {
<UnitControl
{ ...props }
disableUnits={ isMixed }
id={ inputId }
isOnly
value={ parsedQuantity }
onChange={ handleOnChange }
Expand All @@ -98,6 +104,8 @@ export default function AllInputControl( {

<FlexedRangeControl
__nextHasNoMarginBottom
aria-controls={ inputId }
aria-labelledby={ inputId }
hideLabelFromVision
initialPosition={ parsedQuantity ?? 0 }
label={ LABELS.all }
Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/box-control/axial-input-controls.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* WordPress dependencies
*/
import { useInstanceId } from '@wordpress/compose';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -25,6 +29,7 @@ export default function AxialInputControls( {
sides,
...props
}: BoxControlInputControlProps ) {
const inputId = useInstanceId( AxialInputControls, 'box-control-input' );
const createHandleOnFocus =
( side: GroupedSide ) =>
( event: React.FocusEvent< HTMLInputElement > ) => {
Expand Down Expand Up @@ -148,6 +153,7 @@ export default function AxialInputControls( {
<FlexedBoxControlIcon side={ side } sides={ sides } />
<UnitControl
{ ...props }
id={ inputId }
isFirst={ first === side }
isLast={ last === side }
isOnly={ only === side }
Expand All @@ -165,6 +171,8 @@ export default function AxialInputControls( {
/>
<FlexedRangeControl
__nextHasNoMarginBottom
aria-controls={ inputId }
aria-labelledby={ inputId }
hideLabelFromVision
initialPosition={ parsedQuantity ?? 0 }
label={ LABELS[ side ] }
Expand Down
10 changes: 9 additions & 1 deletion packages/components/src/box-control/input-controls.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* WordPress dependencies
*/
import { useInstanceId } from '@wordpress/compose';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -25,6 +29,8 @@ export default function BoxInputControls( {
sides,
...props
}: BoxControlInputControlProps ) {
const inputId = useInstanceId( BoxInputControls, 'box-control-input' );

const createHandleOnFocus =
( side: keyof BoxControlValue ) =>
( event: React.FocusEvent< HTMLInputElement > ) => {
Expand Down Expand Up @@ -122,6 +128,7 @@ export default function BoxInputControls( {
isFirst={ first === side }
isLast={ last === side }
isOnly={ only === side }
id={ inputId }
value={ [ parsedQuantity, computedUnit ].join(
''
) }
Expand All @@ -134,10 +141,11 @@ export default function BoxInputControls( {
/>

<FlexedRangeControl
aria-controls={ inputId }
aria-labelledby={ inputId }
__nextHasNoMarginBottom
hideLabelFromVision
initialPosition={ parsedQuantity ?? 0 }
label={ LABELS[ side ] }
onChange={ ( newValue ) => {
sliderOnChange(
side,
Expand Down

0 comments on commit 3192ad7

Please sign in to comment.