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

Remove usage of aria-details from InputControl and BaseControl. #61203

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Bug Fix

- `BaseControl`, `InputControl`: Remove usage of aria-details from InputControl and BaseControl ([#61203](https://github.com/WordPress/gutenberg/pull/61203)).
- `SlotFill`: fixed missing `getServerSnapshot` parameter in slot map ([#60943](https://github.com/WordPress/gutenberg/pull/60943)).

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/base-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ If true, the label will only be visible to screen readers.

### help

Additional description for the control. It is preferable to use plain text for `help`, as it can be accessibly associated with the control using `aria-describedby`. When the `help` contains links, or otherwise non-plain text content, it will be associated with the control using `aria-details`.
Additional description for the control. The element containing the description will be programmatically associated to the BaseControl by the means of an `aria-describedby` attribute.

- Type: `ReactNode`
- Required: No
Expand Down
6 changes: 1 addition & 5 deletions packages/components/src/base-control/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ export function useBaseControlProps(
preferredId
);

// ARIA descriptions can only contain plain text, so fall back to aria-details if not.
const helpPropName =
typeof help === 'string' ? 'aria-describedby' : 'aria-details';

return {
baseControlProps: {
id: uniqueId,
Expand All @@ -39,7 +35,7 @@ export function useBaseControlProps(
},
controlProps: {
id: uniqueId,
...( !! help ? { [ helpPropName ]: `${ uniqueId }__help` } : {} ),
...( !! help ? { 'aria-describedby': `${ uniqueId }__help` } : {} ),
},
};
}
6 changes: 3 additions & 3 deletions packages/components/src/base-control/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe( 'BaseControl', () => {
).toBeInTheDocument();
} );

it( 'should render help as aria-details when not plain text', () => {
it( 'should still render help as aria-describedby when not plain text', () => {
render(
<MyBaseControl
label="Text"
Expand All @@ -44,10 +44,10 @@ describe( 'BaseControl', () => {
name: 'My help text',
} );

expect( textarea ).toHaveAttribute( 'aria-details' );
expect( textarea ).toHaveAttribute( 'aria-describedby' );
expect(
// eslint-disable-next-line testing-library/no-node-access
help.closest( `#${ textarea.getAttribute( 'aria-details' ) }` )
help.closest( `#${ textarea.getAttribute( 'aria-describedby' ) }` )
).toBeVisible();
} );
} );
3 changes: 1 addition & 2 deletions packages/components/src/base-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export type BaseControlProps = {
/**
* Additional description for the control.
*
* It is preferable to use plain text for `help`, as it can be accessibly associated with the control using `aria-describedby`.
* When the `help` contains links, or otherwise non-plain text content, it will be associated with the control using `aria-details`.
* The element containing the description will be programmatically associated to the BaseControl by the means of an `aria-describedby` attribute.
*/
help?: ReactNode;
/**
Expand Down
5 changes: 1 addition & 4 deletions packages/components/src/input-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ export function UnforwardedInputControl(
onChange,
} );

// ARIA descriptions can only contain plain text, so fall back to aria-details if not.
const helpPropName =
typeof help === 'string' ? 'aria-describedby' : 'aria-details';
const helpProp = !! help ? { [ helpPropName ]: `${ id }__help` } : {};
const helpProp = !! help ? { 'aria-describedby': `${ id }__help` } : {};

return (
<BaseControl
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/input-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ describe( 'InputControl', () => {
).toBeInTheDocument();
} );

it( 'should render help as aria-details when not plain text', () => {
it( 'should still render help as aria-describedby when not plain text', () => {
render( <InputControl help={ <a href="/foo">My help text</a> } /> );

const input = screen.getByRole( 'textbox' );
const help = screen.getByRole( 'link', { name: 'My help text' } );

expect(
// eslint-disable-next-line testing-library/no-node-access
help.closest( `#${ input.getAttribute( 'aria-details' ) }` )
help.closest( `#${ input.getAttribute( 'aria-describedby' ) }` )
).toBeVisible();
} );
} );
Expand Down
Loading