diff --git a/apps/www/src/content/docs/components/input/demo.ts b/apps/www/src/content/docs/components/input/demo.ts index 25778c69c..ecf0f8bfc 100644 --- a/apps/www/src/content/docs/components/input/demo.ts +++ b/apps/www/src/content/docs/components/input/demo.ts @@ -129,6 +129,24 @@ export const sizeChipDemo = { ` }; +export const onValueChangeDemo = { + type: 'code', + code: `function ValueChangeExample() { + const [value, setValue] = React.useState(""); + + return ( + + + Current value: {value || "(empty)"} + + ); +}` +}; + export const interactiveChipDemo = { type: 'code', style: { diff --git a/apps/www/src/content/docs/components/input/index.mdx b/apps/www/src/content/docs/components/input/index.mdx index 5f17e2454..756c8fca1 100644 --- a/apps/www/src/content/docs/components/input/index.mdx +++ b/apps/www/src/content/docs/components/input/index.mdx @@ -16,6 +16,7 @@ import { sizeChipDemo, interactiveChipDemo, withFieldDemo, + onValueChangeDemo, } from "./demo.ts"; @@ -60,6 +61,12 @@ Use Field to add label, description, and error handling. +### Controlled Value + +Use `onValueChange` for a callback that receives only the new string value, or `onChange` for the full React change event. Both fire on every keystroke — pick whichever fits your needs. + + + ### With Prefix/Suffix Input with prefix and suffix text. diff --git a/apps/www/src/content/docs/components/input/props.ts b/apps/www/src/content/docs/components/input/props.ts index 01dab7581..d8e337a4a 100644 --- a/apps/www/src/content/docs/components/input/props.ts +++ b/apps/www/src/content/docs/components/input/props.ts @@ -43,6 +43,18 @@ export interface InputProps { /** Ref to the outer container div. */ containerRef?: React.RefObject; + /** The controlled value of the input. */ + value?: string; + + /** Native change handler. Receives the React change event. */ + onChange?: (event: React.ChangeEvent) => void; + + /** + * Convenience callback fired with the new string value. + * Provided by Base UI's Input primitive — use this when you only need the value. + */ + onValueChange?: (value: string, eventDetails: unknown) => void; + /** Additional CSS class names. */ className?: string; } diff --git a/apps/www/src/content/docs/components/search/demo.ts b/apps/www/src/content/docs/components/search/demo.ts index 26eab6174..c35e4b0c9 100644 --- a/apps/www/src/content/docs/components/search/demo.ts +++ b/apps/www/src/content/docs/components/search/demo.ts @@ -39,3 +39,23 @@ export const clearDemo = { ` }; + +export const onValueChangeDemo = { + type: 'code', + code: `function SearchValueChangeExample() { + const [query, setQuery] = React.useState(""); + + return ( + + setQuery("")} + /> + Query: {query || "(empty)"} + + ); +}` +}; diff --git a/apps/www/src/content/docs/components/search/index.mdx b/apps/www/src/content/docs/components/search/index.mdx index 0ecf20aca..b5f9606ce 100644 --- a/apps/www/src/content/docs/components/search/index.mdx +++ b/apps/www/src/content/docs/components/search/index.mdx @@ -4,7 +4,7 @@ description: A search input component with built-in search icon and optional cle source: packages/raystack/components/search --- -import { playground, sizeDemo, clearDemo } from "./demo.ts"; +import { playground, sizeDemo, clearDemo, onValueChangeDemo } from "./demo.ts"; @@ -38,6 +38,12 @@ The Search component can include a clear button that appears when there is input +### Controlled Value + +Use `onValueChange` to receive only the new query string, or `onChange` for the full React change event. The Search component forwards both to the underlying [Input](/docs/components/input). + + + ## Accessibility The Search component is built with accessibility in mind, following ARIA best practices: diff --git a/apps/www/src/content/docs/components/search/props.ts b/apps/www/src/content/docs/components/search/props.ts index 3f6d212fe..8d04db533 100644 --- a/apps/www/src/content/docs/components/search/props.ts +++ b/apps/www/src/content/docs/components/search/props.ts @@ -17,8 +17,14 @@ export interface SearchProps { /** The controlled value of the input. */ value?: string; - /** Callback when input value changes. */ - onChange?: (value: string) => void; + /** Native change handler. Receives the React change event. */ + onChange?: (event: React.ChangeEvent) => void; + + /** + * Convenience callback fired with the new string value. + * Forwarded to the underlying Input — use this when you only need the value. + */ + onValueChange?: (value: string, eventDetails: unknown) => void; /** Callback when clear button is clicked. */ onClear?: () => void; diff --git a/apps/www/src/content/docs/components/textarea/demo.ts b/apps/www/src/content/docs/components/textarea/demo.ts index c4112175f..c4218c22f 100644 --- a/apps/www/src/content/docs/components/textarea/demo.ts +++ b/apps/www/src/content/docs/components/textarea/demo.ts @@ -71,6 +71,23 @@ export const controlledDemo = { }` }; +export const onValueChangeDemo = { + type: 'code', + code: `function TextAreaValueChangeExample() { + const [value, setValue] = React.useState(''); + + return ( + +