Skip to content

Commit

Permalink
URLInput now always has an ID and accessible label (#40310)
Browse files Browse the repository at this point in the history
* URLInput now always has an ID and accessible label
- Label initialized to null for simpler falsy comparisons
- Duplicate aria-label no longer outputs if a label prop is specified.
  • Loading branch information
iansvo authored Apr 22, 2022
1 parent e7fbb88 commit b19b895
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/block-editor/src/components/url-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ class URLInput extends Component {

renderControl() {
const {
label,
label = null,
className,
isFullWidth,
instanceId,
Expand All @@ -435,15 +435,18 @@ class URLInput extends Component {
suggestionOptionIdPrefix,
} = this.state;

const inputId = `url-input-control-${ instanceId }`;

const controlProps = {
id: `url-input-control-${ instanceId }`,
id: inputId, // Passes attribute to label for the for attribute
label,
className: classnames( 'block-editor-url-input', className, {
'is-full-width': isFullWidth,
} ),
};

const inputProps = {
id: inputId,
value,
required: true,
className: 'block-editor-url-input__input',
Expand All @@ -453,7 +456,7 @@ class URLInput extends Component {
placeholder,
onKeyDown: this.onKeyDown,
role: 'combobox',
'aria-label': __( 'URL' ),
'aria-label': label ? undefined : __( 'URL' ), // Ensure input always has an accessible label
'aria-expanded': showSuggestions,
'aria-autocomplete': 'list',
'aria-owns': suggestionsListboxId,
Expand Down

0 comments on commit b19b895

Please sign in to comment.