ResettableTextInput

<ResettableTextInput> is a <TextInput> with a clear (×) button that resets the field value to an empty string.

Installation

pnpm dlx shadcn@latest add @shadmin/resettable-text-input

Usage

import { ResettableTextInput } from "@/components/admin";
 
<ResettableTextInput source="title" />;

A small ghost button is displayed on the right side of the input when the field has a value. Clicking it sets the field value back to "" and marks the field as dirty.

Props

PropRequiredTypeDefaultDescription
sourceRequiredstring-Field name
classNameOptionalstring-Wrapper classes
clearAlwaysVisibleOptionalbooleanfalseIf true, show a clear button even when the field is empty (it will be disabled)
defaultValueOptionalstring-Default value
disabledOptionalboolean-If true, the input is disabled
formatOptionalfunction-Callback taking the value from the form state, and returning the input value
helperTextOptionalReactNode-Help text
inputClassNameOptionalstring-Classes applied to the underlying <input> element
labelOptionalstring | falseInferredCustom / hide label
parseOptional(value:string) => any-Callback taking the value from the input, and returning the value to be stored in the form state
placeholderOptionalstring-Placeholder text
resettableOptionalbooleantrueIf false, no clear button is displayed
validateOptionalValidator | Validator[]-Validation

Additional props are forwarded to the underlying <TextInput> (and ultimately to the HTML <input>).

resettable

Set resettable to false to hide the clear button entirely. The component then behaves like a regular <TextInput>:

<ResettableTextInput source="title" resettable={false} />

clearAlwaysVisible

By default, the clear button is only shown when the field has a value. Set clearAlwaysVisible to true to render it permanently. The button will be disabled when the field is empty:

<ResettableTextInput source="title" clearAlwaysVisible />