SearchInput
Basic search input field with clear button.
#
Documentation
#
#
Usage
#
The SearchInput
component extends the Input
component with some additional addons.
import type { ComponentPropsWithoutRef } from "react";
import { Field, SearchInput } from "@optiaxiom/react";
export function App({
description,
error,
label = "Search label",
required = false,
}: Pick<
ComponentPropsWithoutRef<typeof Field>,
"description" | "error" | "label" | "required"
>) {
return (
<Field
description={description}
error={error}
label={label}
required={required}
>
<SearchInput placeholder="Enter text..." w="224" />
</Field>
);
}
#
Disabled state
#
Enable the disabled
prop to toggle the disabled state of the input field.
import { SearchInput } from "@optiaxiom/react";
export function App() {
return <SearchInput defaultValue="Some disabled value" disabled w="224" />;
}
#
Controlled
#
Use the value
and defaultValue
props to toggle between controlled and uncontrolled usage. And combine it with onChange
to listen for changes to the input field.
import { Button, Flex, SearchInput } from "@optiaxiom/react";
import { useRef, useState } from "react";
export function App() {
const [value, setValue] = useState("");
const ref = useRef<HTMLInputElement>(null);
return (
<Flex>
<SearchInput
onChange={(event) => setValue(event.target.value)}
ref={ref}
value={value}
w="224"
/>
<Flex flexDirection="row">
<Button
onClick={() => {
setValue("sample");
ref.current?.focus();
}}
>
Set Value
</Button>
<Button disabled={!value} onClick={() => setValue("")}>
Reset
</Button>
</Flex>
</Flex>
);
}
#
Related
#
Input
Basic text field for capturing user input.
Textarea
Multi-line text field for capturing user input.
#
Props
#
#
SearchInput
#
Supports all Input props in addition to its own. Renders a <div>
element but forwards all props to an inner <input>
element.
Prop |
---|
addonAfter Display content inside the input at the end.
|
addonBefore Display content inside the input at the start.
|
addonPointerEvents When this prop is set to
|
appearance Control the appearance of the input.
|
asChild Change the default rendered element for the one passed as a child, merging their props and behavior. Read the Composition guide for more details.
|
className
|
disabled Whether the input is disabled.
|
error Whether to show the input error state.
|
htmlSize Control the native input
|
onValueClear
|
size Control the size of the input.
|
#
Changelog
#
#
0.1.0
#
- Added component