Skip to content

Commit

Permalink
Clarify id description
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Mar 15, 2022
1 parent e2b842f commit e53fca1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
16 changes: 9 additions & 7 deletions packages/components/src/base-control/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# BaseControl

BaseControl component is used to generate labels and help text for components handling user inputs.
`BaseControl` is a component used to generate labels and help text for components handling user inputs.

## Usage

Render a BaseControl for a textarea input:
Render a `BaseControl` for a textarea input:

```jsx
import { BaseControl } from '@wordpress/components';

// The `id` prop is necessary to accessibly associate the label with the textarea
const MyBaseControl = () => (
<BaseControl id="textarea-1" label="Text" help="Enter some text" __nextHasNoMarginBottom={ true }>
<textarea id="textarea-1" />
Expand All @@ -22,10 +23,10 @@ The component accepts the following props:

### id

The id of the element to which labels and help text are being generated. That element should be passed as a child.
The HTML `id` of the element (passed in as a child to `BaseControl`) to which labels and help text are being generated. This is necessary to accessibly associate the label with that element.

- Type: `String`
- Required: Yes
- Required: No

### label

Expand Down Expand Up @@ -73,16 +74,17 @@ Start opting into the new margin-free styles that will become the default in a f

## BaseControl.VisualLabel

`BaseControl.VisualLabel` component is used to render a purely visual label inside a `BaseControl` component.
It should only be used in cases where the children being rendered inside BaseControl are already properly labeled, e.g., a button, but we want an additional visual label for that section equivalent to the labels BaseControl would otherwise use if the label prop was passed.
`BaseControl.VisualLabel` is used to render a purely visual label inside a `BaseControl` component.

It should only be used in cases where the children being rendered inside BaseControl are already accessibly labeled, e.g., a button, but we want an additional visual label for that section equivalent to the labels `BaseControl` would otherwise use if the `label` prop was passed.

## Usage

```jsx
import { BaseControl } from '@wordpress/components';

const MyBaseControl = () => (
<BaseControl help="Pressing the Select an author button will open a modal that allows an advanced mechanism for author selection">
<BaseControl help="This button is already accessibly labeled.">
<BaseControl.VisualLabel>Author</BaseControl.VisualLabel>
<Button>Select an author</Button>
</BaseControl>
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/base-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
* // Render a `BaseControl` for a textarea input
* import { BaseControl } from '@wordpress/components';
*
* // The `id` prop is necessary to accessibly associate the label with the textarea
* const MyBaseControl = () => (
* <BaseControl id="textarea-1" label="Text" help="Enter some text" __nextHasNoMarginBottom={ true }>
* <textarea id="textarea-1" />
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/base-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export type BaseControlProps = {
*/
__nextHasNoMarginBottom?: boolean;
/**
* The id of the element to which labels and help text are being generated.
* That element should be passed as a child.
* The HTML `id` of the element (passed in as a child to `BaseControl`) to which labels and help text are being generated.
* This is necessary to accessibly associate the label with that element.
*/
id?: string;
/**
Expand Down

0 comments on commit e53fca1

Please sign in to comment.