Skip to content

Commit

Permalink
Simplify fieldset labeling to avoid repetition.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Feb 3, 2025
1 parent d8fd7b0 commit 15dd976
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/components/src/font-size-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { ForwardedRef } from 'react';
import { __ } from '@wordpress/i18n';
import { settings } from '@wordpress/icons';
import { useState, forwardRef } from '@wordpress/element';
import { useInstanceId } from '@wordpress/compose';

/**
* Internal dependencies
Expand All @@ -21,7 +22,6 @@ import {
parseQuantityAndUnitFromRawValue,
useCustomUnits,
} from '../unit-control';
import { VisuallyHidden } from '../visually-hidden';
import type { FontSizePickerProps } from './types';
import { Container, Header, HeaderLabel, HeaderToggle } from './styles';
import { Spacer } from '../spacer';
Expand Down Expand Up @@ -50,6 +50,11 @@ const UnforwardedFontSizePicker = (
withReset = true,
} = props;

const labelId = useInstanceId(
UnforwardedFontSizePicker,
'font-size-picker-label'
);

const units = useCustomUnits( {
availableUnits: unitsProp,
} );
Expand Down Expand Up @@ -100,11 +105,17 @@ const UnforwardedFontSizePicker = (
} );

return (
<Container ref={ ref } className="components-font-size-picker">
<VisuallyHidden as="legend">{ __( 'Font size' ) }</VisuallyHidden>
<Container
ref={ ref }
className="components-font-size-picker"
// This Container component renders a fieldset element that needs to be labeled.
aria-labelledby={ labelId }
>
<Spacer>
<Header className="components-font-size-picker__header">
<HeaderLabel>{ __( 'Font size' ) }</HeaderLabel>
<HeaderLabel id={ labelId }>
{ __( 'Font size' ) }
</HeaderLabel>
{ ! disableCustomFontSizes && (
<HeaderToggle
label={
Expand Down

0 comments on commit 15dd976

Please sign in to comment.