Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Revert "move search to text-field"

Oleg Isonenab3e6f2f87ae
diff --git a/apps/designer/app/designer/features/style-panel/search.tsx b/apps/designer/app/designer/features/style-panel/search.tsx
index b3d2b67662..6feccbdf95 100644
--- a/apps/designer/app/designer/features/style-panel/search.tsx
+++ b/apps/designer/app/designer/features/style-panel/search.tsx
@@ -21,13 +21,30 @@ type SearchProps = {
export const Search = ({ onSearch }: SearchProps) => {
const [search, setSearch] = useSearch(onSearch);
+ const inputRef = useRef<HTMLInputElement>(null);
return (
<TextField
type="search"
value={search}
- onCancel={() => {
- setSearch("");
- }}
+ inputRef={inputRef}
+ prefix={
+ <IconButton aria-label="Search" css={{ color: "$hint" }} tabIndex={-1}>
+ <MagnifyingGlassIcon />
+ </IconButton>
+ }
+ suffix={
+ search.length > 0 && (
+ <IconButton
+ aria-label="Reset search"
+ onClick={() => {
+ setSearch("");
+ inputRef.current?.focus();
+ }}
+ >
+ <Cross2Icon />
+ </IconButton>
+ )
+ }
placeholder="Search"
onChange={(event) => {
const { value } = event.target;
diff --git a/packages/design-system/src/components/text-field.tsx b/packages/design-system/src/components/text-field.tsx
index c4d58f35d3..8eaf9261a5 100644
--- a/packages/design-system/src/components/text-field.tsx
+++ b/packages/design-system/src/components/text-field.tsx
@@ -3,8 +3,6 @@ import React from "react";
import { useFocusWithin } from "@react-aria/interactions";
import { styled } from "../stitches.config";
import { Flex } from "./flex";
-import { IconButton } from "./icon-button";
-import { Cross2Icon, MagnifyingGlassIcon } from "@webstudio-is/icons";
const InputBase = styled("input", {
// Reset
@@ -157,7 +155,6 @@ export type TextFieldProps = Pick<
inputRef?: React.Ref<HTMLInputElement>;
prefix?: React.ReactNode;
suffix?: React.ReactNode;
- onCancel?: () => void;
};
export const TextField = React.forwardRef<HTMLDivElement, TextFieldProps>(
@@ -172,9 +169,6 @@ export const TextField = React.forwardRef<HTMLDivElement, TextFieldProps>(
variant,
onFocus,
onBlur,
- onCancel,
- type,
- value,
...textFieldProps
} = props;
@@ -196,33 +190,6 @@ export const TextField = React.forwardRef<HTMLDivElement, TextFieldProps>(
},
});
- const prefixOrSearch =
- type === "search" ? (
- <IconButton aria-label="Search" css={{ color: "$hint" }} tabIndex={-1}>
- <MagnifyingGlassIcon />
- </IconButton>
- ) : (
- prefix
- );
-
- const inActiveSearch =
- type === "search" && value !== undefined && String(value).length !== 0;
-
- const suffixOrCancel = inActiveSearch ? (
- <IconButton
- aria-label="Reset search"
- tabIndex={-1}
- onClick={() => {
- internalInputRef.current?.focus();
- onCancel?.();
- }}
- >
- <Cross2Icon />
- </IconButton>
- ) : (
- suffix
- );
-
return (
<TextFieldBase
{...focusWithinProps}
@@ -231,20 +198,18 @@ export const TextField = React.forwardRef<HTMLDivElement, TextFieldProps>(
state={state}
variant={variant}
css={css}
- withPrefix={Boolean(prefixOrSearch)}
- withSuffix={Boolean(suffixOrCancel)}
+ withPrefix={Boolean(prefix)}
+ withSuffix={Boolean(suffix)}
onClickCapture={focusInnerInput}
>
{/* We want input to be the first element in DOM so it receives the focus first */}
<InputBase
- {...textFieldProps}
disabled={disabled}
- type={type}
- value={value}
+ {...textFieldProps}
ref={mergeRefs(internalInputRef, inputRef ?? null)}
/>
- {prefixOrSearch && (
+ {prefix && (
<Flex
css={{
alignItems: "center",
@@ -252,11 +217,11 @@ export const TextField = React.forwardRef<HTMLDivElement, TextFieldProps>(
order: 0,
}}
>
- {prefixOrSearch}
+ {prefix}
</Flex>
)}
- {suffixOrCancel && (
+ {suffix && (
<Flex
css={{
alignItems: "center",
@@ -264,7 +229,7 @@ export const TextField = React.forwardRef<HTMLDivElement, TextFieldProps>(
order: 2,
}}
>
- {suffixOrCancel}
+ {suffix}
</Flex>
)}
</TextFieldBase>