From b19b895620fc78ac27b69eda2153abe137ff9f9b Mon Sep 17 00:00:00 2001 From: Ian Svoboda Date: Fri, 22 Apr 2022 05:53:29 -0400 Subject: [PATCH] URLInput now always has an ID and accessible label (#40310) * 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. --- packages/block-editor/src/components/url-input/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/url-input/index.js b/packages/block-editor/src/components/url-input/index.js index 7df591e8b673e..51132f07179fd 100644 --- a/packages/block-editor/src/components/url-input/index.js +++ b/packages/block-editor/src/components/url-input/index.js @@ -418,7 +418,7 @@ class URLInput extends Component { renderControl() { const { - label, + label = null, className, isFullWidth, instanceId, @@ -435,8 +435,10 @@ 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, @@ -444,6 +446,7 @@ class URLInput extends Component { }; const inputProps = { + id: inputId, value, required: true, className: 'block-editor-url-input__input', @@ -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,