Skip to content

Commit

Permalink
Fix Nav Submenu block Link UI text control (#46243)
Browse files Browse the repository at this point in the history
* Add hasTextControl to submenu LinkControl

* Clean up unnecessary prop={ true } in submenu LinkControl

* Add JSDoc for hasTextConrtol prop to LinkControl

* Fix missing label in dropdown

* Use stripHTML for the title/label
  • Loading branch information
Alex Lende authored Dec 2, 2022
1 parent 5e821f2 commit 7f8e24d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import { DEFAULT_LINK_SETTINGS } from './constants';
* @property {boolean=} withCreateSuggestion Whether to allow creation of link value from suggestion.
* @property {Object=} suggestionsQuery Query parameters to pass along to wp.blockEditor.__experimentalFetchLinkSuggestions.
* @property {boolean=} noURLSuggestion Whether to add a fallback suggestion which treats the search query as a URL.
* @property {boolean=} hasTextControl Whether to add a text field to the UI to update the value.title.
* @property {string|Function|undefined} createSuggestionButtonText The text to use in the button that calls createSuggestion.
* @property {Function} renderControlBottom Optional controls to be rendered at the bottom of the component.
*/
Expand Down
9 changes: 7 additions & 2 deletions packages/block-library/src/navigation-submenu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import {
useRef,
createInterpolateElement,
} from '@wordpress/element';
import { placeCaretAtHorizontalEdge } from '@wordpress/dom';
import {
placeCaretAtHorizontalEdge,
__unstableStripHTML as stripHTML,
} from '@wordpress/dom';
import { link as linkIcon, removeSubmenu } from '@wordpress/icons';
import {
useResourcePermissions,
Expand Down Expand Up @@ -284,6 +287,7 @@ export default function NavigationSubmenuEdit( {
const { label, type, opensInNewTab, url, description, rel, title, kind } =
attributes;
const link = {
title: label && stripHTML( label ),
url,
opensInNewTab,
};
Expand Down Expand Up @@ -665,7 +669,8 @@ export default function NavigationSubmenuEdit( {
<LinkControl
className="wp-block-navigation-link__inline-link-input"
value={ link }
showInitialSuggestions={ true }
hasTextControl
showInitialSuggestions
withCreateSuggestion={ userCanCreate }
createSuggestion={ handleCreate }
createSuggestionButtonText={ ( searchTerm ) => {
Expand Down

0 comments on commit 7f8e24d

Please sign in to comment.