|
2 | 2 | * WordPress dependencies
|
3 | 3 | */
|
4 | 4 | import { __, sprintf } from '@wordpress/i18n';
|
5 |
| -import { VisuallyHidden } from '@wordpress/components'; |
| 5 | +import { VisuallyHidden, MenuGroup } from '@wordpress/components'; |
6 | 6 |
|
7 | 7 | /**
|
8 | 8 | * External dependencies
|
@@ -72,59 +72,61 @@ export default function LinkControlSearchResults( {
|
72 | 72 | className={ resultsListClasses }
|
73 | 73 | aria-labelledby={ searchResultsLabelId }
|
74 | 74 | >
|
75 |
| - { suggestions.map( ( suggestion, index ) => { |
76 |
| - if ( |
77 |
| - shouldShowCreateSuggestion && |
78 |
| - CREATE_TYPE === suggestion.type |
79 |
| - ) { |
| 75 | + <MenuGroup> |
| 76 | + { suggestions.map( ( suggestion, index ) => { |
| 77 | + if ( |
| 78 | + shouldShowCreateSuggestion && |
| 79 | + CREATE_TYPE === suggestion.type |
| 80 | + ) { |
| 81 | + return ( |
| 82 | + <LinkControlSearchCreate |
| 83 | + searchTerm={ currentInputValue } |
| 84 | + buttonText={ createSuggestionButtonText } |
| 85 | + onClick={ () => |
| 86 | + handleSuggestionClick( suggestion ) |
| 87 | + } |
| 88 | + // Intentionally only using `type` here as |
| 89 | + // the constant is enough to uniquely |
| 90 | + // identify the single "CREATE" suggestion. |
| 91 | + key={ suggestion.type } |
| 92 | + itemProps={ buildSuggestionItemProps( |
| 93 | + suggestion, |
| 94 | + index |
| 95 | + ) } |
| 96 | + isSelected={ index === selectedSuggestion } |
| 97 | + /> |
| 98 | + ); |
| 99 | + } |
| 100 | + |
| 101 | + // If we're not handling "Create" suggestions above then |
| 102 | + // we don't want them in the main results so exit early. |
| 103 | + if ( CREATE_TYPE === suggestion.type ) { |
| 104 | + return null; |
| 105 | + } |
| 106 | + |
80 | 107 | return (
|
81 |
| - <LinkControlSearchCreate |
82 |
| - searchTerm={ currentInputValue } |
83 |
| - buttonText={ createSuggestionButtonText } |
84 |
| - onClick={ () => |
85 |
| - handleSuggestionClick( suggestion ) |
86 |
| - } |
87 |
| - // Intentionally only using `type` here as |
88 |
| - // the constant is enough to uniquely |
89 |
| - // identify the single "CREATE" suggestion. |
90 |
| - key={ suggestion.type } |
| 108 | + <LinkControlSearchItem |
| 109 | + key={ `${ suggestion.id }-${ suggestion.type }` } |
91 | 110 | itemProps={ buildSuggestionItemProps(
|
92 | 111 | suggestion,
|
93 | 112 | index
|
94 | 113 | ) }
|
| 114 | + suggestion={ suggestion } |
| 115 | + index={ index } |
| 116 | + onClick={ () => { |
| 117 | + handleSuggestionClick( suggestion ); |
| 118 | + } } |
95 | 119 | isSelected={ index === selectedSuggestion }
|
| 120 | + isURL={ LINK_ENTRY_TYPES.includes( |
| 121 | + suggestion.type |
| 122 | + ) } |
| 123 | + searchTerm={ currentInputValue } |
| 124 | + shouldShowType={ shouldShowSuggestionsTypes } |
| 125 | + isFrontPage={ suggestion?.isFrontPage } |
96 | 126 | />
|
97 | 127 | );
|
98 |
| - } |
99 |
| - |
100 |
| - // If we're not handling "Create" suggestions above then |
101 |
| - // we don't want them in the main results so exit early. |
102 |
| - if ( CREATE_TYPE === suggestion.type ) { |
103 |
| - return null; |
104 |
| - } |
105 |
| - |
106 |
| - return ( |
107 |
| - <LinkControlSearchItem |
108 |
| - key={ `${ suggestion.id }-${ suggestion.type }` } |
109 |
| - itemProps={ buildSuggestionItemProps( |
110 |
| - suggestion, |
111 |
| - index |
112 |
| - ) } |
113 |
| - suggestion={ suggestion } |
114 |
| - index={ index } |
115 |
| - onClick={ () => { |
116 |
| - handleSuggestionClick( suggestion ); |
117 |
| - } } |
118 |
| - isSelected={ index === selectedSuggestion } |
119 |
| - isURL={ LINK_ENTRY_TYPES.includes( |
120 |
| - suggestion.type |
121 |
| - ) } |
122 |
| - searchTerm={ currentInputValue } |
123 |
| - shouldShowType={ shouldShowSuggestionsTypes } |
124 |
| - isFrontPage={ suggestion?.isFrontPage } |
125 |
| - /> |
126 |
| - ); |
127 |
| - } ) } |
| 128 | + } ) } |
| 129 | + </MenuGroup> |
128 | 130 | </div>
|
129 | 131 | </div>
|
130 | 132 | );
|
|
0 commit comments