diff --git a/packages/block-editor/src/components/inserter/style.scss b/packages/block-editor/src/components/inserter/style.scss
index dd0cc50e31fcb4..35c18e1d9acce5 100644
--- a/packages/block-editor/src/components/inserter/style.scss
+++ b/packages/block-editor/src/components/inserter/style.scss
@@ -108,10 +108,6 @@ $block-inserter-tabs-height: 44px;
.block-editor-inserter__search {
padding: $grid-unit-20 $grid-unit-20 0 $grid-unit-20;
-
- .components-search-control__icon {
- right: $grid-unit-10 + ($grid-unit-60 - $icon-size) * 0.5;
- }
}
.block-editor-inserter__tabs {
@@ -615,15 +611,9 @@ $block-inserter-tabs-height: 44px;
}
.block-editor-inserter__media-panel-search {
- &.components-search-control {
- input[type="search"].components-search-control__input {
- background: $white;
- }
- button.components-button {
- min-width: auto;
- padding-left: $grid-unit-05 * 0.5;
- padding-right: $grid-unit-05 * 0.5;
- }
+ // TODO: Consider using the Theme component to automatically adapt to a gray background.
+ &:not(:focus-within) {
+ --wp-components-color-background: #{$white};
}
}
}
diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md
index fe71930db85dd3..5d3d580018f838 100644
--- a/packages/components/CHANGELOG.md
+++ b/packages/components/CHANGELOG.md
@@ -41,6 +41,7 @@
- Removing Reakit as a dependency of the components package ([#58631](https://github.com/WordPress/gutenberg/pull/58631)).
- `CustomSelect`: add unit tests ([#58583](https://github.com/WordPress/gutenberg/pull/58583)).
- `InputBase`: Add `isBorderless` prop ([#58750](https://github.com/WordPress/gutenberg/pull/58750)).
+- `SearchControl`: Replace internal implementation to use `InputControl` ([#56524](https://github.com/WordPress/gutenberg/pull/56524)).
## 25.16.0 (2024-01-24)
diff --git a/packages/components/src/navigation/menu/menu-title-search.tsx b/packages/components/src/navigation/menu/menu-title-search.tsx
index d03766f28d7522..c1dbda5af88fb0 100644
--- a/packages/components/src/navigation/menu/menu-title-search.tsx
+++ b/packages/components/src/navigation/menu/menu-title-search.tsx
@@ -10,10 +10,11 @@ import { __, _n, sprintf } from '@wordpress/i18n';
import withSpokenMessages from '../../higher-order/with-spoken-messages';
import { useNavigationMenuContext } from './context';
import { useNavigationContext } from '../context';
-import { MenuTitleSearchUI } from '../styles/navigation-styles';
import { SEARCH_FOCUS_DELAY } from '../constants';
import type { NavigationMenuTitleSearchProps } from '../types';
+import SearchControl from '../../search-control';
+import { MenuTitleSearchControlWrapper } from '../styles/navigation-styles';
function MenuTitleSearch( {
debouncedSpeak,
@@ -80,9 +81,9 @@ function MenuTitleSearch( {
).trim();
return (
-
-
+ onSearch?.( value ) }
@@ -90,10 +91,9 @@ function MenuTitleSearch( {
placeholder={ placeholder }
onClose={ onClose }
ref={ inputRef }
- type="search"
value={ search }
/>
-
+
);
}
diff --git a/packages/components/src/navigation/styles/navigation-styles.tsx b/packages/components/src/navigation/styles/navigation-styles.tsx
index 27c508b98f26dc..820cf2224be885 100644
--- a/packages/components/src/navigation/styles/navigation-styles.tsx
+++ b/packages/components/src/navigation/styles/navigation-styles.tsx
@@ -17,7 +17,6 @@ import { Text } from '../../text';
import { Heading } from '../../heading';
import { reduceMotion, rtl } from '../../utils';
import { space } from '../../utils/space';
-import SearchControl from '../../search-control';
export const NavigationUI = styled.div`
width: 100%;
@@ -69,6 +68,11 @@ export const MenuTitleUI = styled.div`
width: 100%;
`;
+export const MenuTitleSearchControlWrapper = styled.div`
+ margin: 11px 0; // non-ideal hardcoding to maintain same height as Heading, could be improved
+ padding: 1px; // so the focus border doesn't get cut off by the overflow hidden on MenuTitleUI
+`;
+
export const MenuTitleActionsUI = styled.span`
height: ${ space( 6 ) }; // 24px, same height as the buttons inside
@@ -91,32 +95,6 @@ export const MenuTitleActionsUI = styled.span`
}
`;
-export const MenuTitleSearchUI = styled( SearchControl )`
- input[type='search'].components-search-control__input {
- margin: 0;
- background: #303030;
- color: #fff;
-
- &:focus {
- background: #434343;
- color: #fff;
- }
-
- &::placeholder {
- color: rgba( 255, 255, 255, 0.6 );
- }
- }
-
- svg {
- fill: white;
- }
-
- .components-button.has-icon {
- padding: 0;
- min-width: auto;
- }
-`;
-
export const GroupTitleUI = styled( Heading )`
min-height: ${ space( 12 ) };
align-items: center;
diff --git a/packages/components/src/search-control/README.md b/packages/components/src/search-control/README.md
index c52256b951ebba..52513ab47f582e 100644
--- a/packages/components/src/search-control/README.md
+++ b/packages/components/src/search-control/README.md
@@ -20,6 +20,7 @@ function MySearchControl( { className, setState } ) {
return (
;
+ }
+
+ const onReset = () => {
+ onChange( '' );
+ searchRef.current?.focus();
+ };
+
+ return (
+
+ );
+}
function UnforwardedSearchControl(
{
- __nextHasNoMarginBottom,
- __next40pxDefaultSize = false,
+ __nextHasNoMarginBottom = false,
className,
onChange,
- onKeyDown,
value,
- label,
+ label = __( 'Search' ),
placeholder = __( 'Search' ),
hideLabelFromVision = true,
- help,
onClose,
size = 'default',
...restProps
- }: WordPressComponentProps< SearchControlProps, 'input', false >,
+ }: Omit<
+ WordPressComponentProps< SearchControlProps, 'input', false >,
+ // TODO: Background styling currently doesn't support a disabled state. Needs design work.
+ 'disabled'
+ >,
forwardedRef: ForwardedRef< HTMLInputElement >
) {
- const searchRef = useRef< HTMLInputElement >();
- const instanceId = useInstanceId( SearchControl );
- const id = `components-search-control-${ instanceId }`;
-
- const renderRightButton = () => {
- if ( onClose ) {
- return (
-
- );
- }
+ // @ts-expect-error The `disabled` prop is not yet supported in the SearchControl component.
+ // Work with the design team (@WordPress/gutenberg-design) if you need this feature.
+ delete restProps.disabled;
- if ( !! value ) {
- return (
-