SearchInput
Captures a search query, with an icon for the search state and a button to clear it.
partially-compliant
- Overview
- Props
- Figma
Usage
This is a particular TextInput to capture a search query from the user.
There is a side icon to indicate the search action or progress.
There is a reset button to clear the input.
Basic Usage
Progress
You can give feedback to the user by showing a progress indicator.
Reset Button
You can add a reset button to clear the input.
Smallest Size
By default, the size of the SearchInput is md, which is 46px in height. You can align it to the small button size by specifying the sm size.
Accessibility
You need to provide a label, a placeholder or an aria-label, so the field has an accessible name.
A renderPlaceholder cannot be read as text, so it always comes with a label or an aria-label.
RAWeb 1.1 criterion 11.1 never accepts a placeholder as a label: it is not exposed as one, and it disappears as soon as the user types. Two tests apply to a search field, and they ask different things:
- 11.1.1 wants an accessible name, which a
label, anaria-labelor atitleall provide. - 11.1.3 wants that name readable on screen when it is not visible, which only a
titleor text sitting next to the field provides. Anaria-labelalone does not close it.
So without a visible label, SearchInput copies the placeholder into the title attribute. That
covers 11.1.3 on its own, and the RGAA requires the two to be identical when both are set, which
holds here by construction. Nothing to pass, and the hover tooltip is the only visible change.
Pass an aria-label on top when the placeholder lists what can be typed rather than naming the
field. It becomes the accessible name, so a screen reader announces the purpose then the expected
input, and criterion 11.2 is then judged on it rather than on the title:
<SearchInput aria-label="Search for an employee" placeholder="Name, email, employee ID" />
label and aria-label cannot be combined, since the aria-label would replace the visible label as
the accessible name. A visible label also drops the title, which would only repeat it.
Playground
murray and murray/mobile.SearchInput props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| aria-describedby | stringundefined | Id of an element outside the input that also describes it, such as an error shared by several inputs | ||
| aria-label | stringundefined | Accessibility label, only necessary when not associated with a label Accessible name of the field, used when there is no `label` | ||
| aria-required | booleanundefined | Overrides `aria-required` set by `required`, to mark the input as mandatory without the asterisk | ||
| autoFocus | booleanundefined | If true, focuses the input on componentDidMount.The default value is false. | ||
| cursor | Cursorundefined | Enforce a cursor type | ||
| defaultValue | stringundefined | Uncontrolled default value. | ||
| disabled | booleanundefined | Disable input | ||
| enterKeyHint | 6 possibilities"search""done""go""next""send"undefined | |||
| error | ReactNode | Contents of `InputErrorNext` component, if not set, error is not rendered. | ||
| focused | booleanundefined | Show focus styles even when the input isn't focused, e.g. while a readonly input's picker is open | ||
| groupLabel | ReactNode | Name of the group the input belongs to, such as the date its day field is part of. VoiceOver and TalkBack don't announce it when focus lands on the input, so on native it ends the input's accessible name, after `label`. Ignored without a `label`. | ||
| helpText | ReactNode | Contents of `InputHelpTextNext` component, if not set, description is not rendered. | ||
| iconVisual | 336 possibilities"Card""Menu""Accessible""AlanBlobHappy""AlanBlobHey""AlanBlobNoMouth""AlanBlobOpenMouth""AlanBlobSleeping""AlanLogo""Album""Alert""AlertAlt""Ambulance""AmbulanceSiren""Apple""AppleFilled""ArrowBottomLeft""ArrowBottomRight""ArrowDouble""ArrowDown""ArrowDownAlt""ArrowDropdown""ArrowDropright""ArrowDropup""ArrowLeft""ArrowLeftAlt""ArrowRight""ArrowRightAlt""ArrowTopLeft""ArrowTopRight""ArrowUp""ArrowUpAlt""ArrowUpDown""ArrowsLeftRight""Baby""BabyBottle""Back10""BadgeHeart""Bag""Bandaid""Bank""Bell""BellRinging""Bike""Bills""BirthdayCake""Block""BlurHeavy""BlurLight""BookHeart""Books""BooksAlt""BoxAdd""BoxArrowTopRight""Brain""Bubble""BubbleHeart""BubbleWithDots""Bus""Calculator""Calendar""CalendarClock""Camera""Cards""Carrot""ChatAdd""ChatAddFilled""ChatBubble""ChatDots""Check""CheckAlt""CheckboxActive""CheckboxInactive""Child""Children""Close""CloseAlt""CloudDownload""CloudUpload""Coffee""Company""Copy""Cross""DashboardMenuRight""DashboardMenuRightFilled""Devices""DockToBottom""DockToRight""Doctor""DoctorBag""Document""DocumentHeart""DotMenu""DoubleCheck""Driving""Drop""Dumbbells""Ear""Email""Enterprise""Euro""ExclamationMark""ExitFullscreen""ExternalLink""Eye""EyeOff""EyeOffStroke""FaceId""Facebook""FatArrowRight""FeatherPen""Female""FileUnknown""Filter""Finger""Flag""Flash""FlashDouble""FlashNo""FlashOutline""FlashYes""FlipCamera""Foot""Forward10""FrameProfile""FrameSearch""Fullscreen""Gender""Gift""GiftMind""Glasses""Globe""GlobeEarth""Graph""GraphicEq""Hand""HangUp""Heart""HeartAdd""HeartCheck""HeartStroke""HeartStrokeAdd""Home""HomeHeart""HomeMap""Hospital""HospitalMap""Hourglass""Intercom""Journal""Key""Keyboard""Label""LaptopHealth""Leaves""Levers""Lifebuoy""LightBulb""Link""Linkedin""List""Location""Lock""LockOpen""Lotus""MagnifyingGlass""Mail""Male""Map""MapLocation""Masterclass""MedicalChat""MedicalChatHeart""Medium""MenuDot""Mic""MicOff""Microscope""MindCard""MindInbox""MinusAlt""MobilePhone""Moon""MoonSleepy""MusicOff""MusicOffSingle""MusicOn""MusicOnSingle""NearMe""NewPost""NoFlash""NoSmoking""None""NoteAdd""Notion""PanelLeft""PanelLeftDashed""Paperclip""Paperplane""Pause""Payfit""PeachFilled""Pencil""People""PeopleTwo""PersonAdd""PersonRemove""Phone""PhoneHangUp""PhonePlus""Picture""Piggy""Pill""Pills""Play""Plus""PlusAlt""PrevenirLogo""Printer""Profile""ProfileSettings""Psychology""Quotes""RaisingHands""React""Refresh""Reply""Rotate""RotateBox""RoundedArrowDown""RoundedArrowLeft""RoundedArrowRight""RoundedArrowUp""RoundedCheck""RoundedCross""RoundedEmpty""RoundedExclamationMark""RoundedFull""RoundedHalf""RoundedHelp""RoundedHelpLine""RoundedInfo""RoundedInfoLine""RoundedLess""RoundedPlay""RoundedPlus""RoundedQuarter""RoundedThreeQuarters""RoundedWarning""Ruler""RulerFilled""Save""Scale""ScanBarcode""Screenshare""ScreenshareStop""Seringe""Settings""Share""ShareAndroid""ShareIos""ShareScreen""Shield""ShieldCog""ShieldHeart""Snowflake""SocialFb""SocialFbLine""SocialGoogle""SocialLinkedin""SocialLinkedinLine""SocialTwitter""SocialTwitterLine""Sparkles""Spiral""SplitLeft""SplitRight""SsoGoogle""SsoPsc""Star""Stethoscope""StoreBasket""StrawberryFilled""Subtitles""Subway""Sun""Swipe""Target""ThumbDownStroke""ThumbUpStroke""ThumbsDown""ThumbsUp""Tick""Time""TimeSimple""Tooth""ToothBrace""TouchId""TpCard""Tram""Transmission""TransportationBus""TransportationTrain""Trash""TreeGraph""TriangularExclamationMark""TurtleShell""Twitter""Umbrella""UmbrellaHeart""Undo""VideoCall""VideoHeart""VideoHorizontal""VideoHorizontalOutlined""VideoOff""VideoOn""VideoPlural""VideoVertical""VolumeOff""VolumeOn""VolumeUp""Walking""Wallet""Warning""WarningAlt""Wind""Work""WorkHeart""World""Wrench""X""ZoomIn""ZoomOut"nullundefined | |||
| id | stringundefined | ID of the input. Will use a generated id by default | ||
| label | 80 possibilitiesundefinednullstringnumberbigintfalsetrueReactElement<unknown, stringJSXElementConstructor<any>>Iterable<ReactNode>ReactPortalPromise<AwaitedReactNode>string & ReactElement<unknown, stringJSXElementConstructor<any>>string & Iterable<ReactNode>string & ReactPortalstring & Promise<AwaitedReactNode>number & ReactElement<unknown, stringJSXElementConstructor<any>>number & Iterable<ReactNode>number & ReactPortalnumber & Promise<AwaitedReactNode>bigint & ReactElement<unknown, stringJSXElementConstructor<any>>bigint & Iterable<ReactNode>bigint & ReactPortalbigint & Promise<AwaitedReactNode>false & ReactElement<unknown, stringJSXElementConstructor<any>>false & Iterable<ReactNode>false & ReactPortalfalse & Promise<AwaitedReactNode>true & ReactElement<unknown, stringJSXElementConstructor<any>>true & Iterable<ReactNode>true & ReactPortaltrue & Promise<AwaitedReactNode>ReactElement<unknown, stringJSXElementConstructor<any>> & stringReactElement<unknown, stringJSXElementConstructor<any>> & numberReactElement<unknown, stringJSXElementConstructor<any>> & bigintReactElement<unknown, stringJSXElementConstructor<any>> & falseReactElement<unknown, stringJSXElementConstructor<any>> & trueReactElement<unknown, stringJSXElementConstructor<any>> & Iterable<ReactNode>ReactElement<unknown, stringJSXElementConstructor<any>> & ReactPortalReactElement<unknown, stringJSXElementConstructor<any>> & Promise<AwaitedReactNode>Iterable<ReactNode> & stringIterable<ReactNode> & numberIterable<ReactNode> & bigintIterable<ReactNode> & falseIterable<ReactNode> & trueIterable<ReactNode> & ReactElement<unknown, stringJSXElementConstructor<any>>Iterable<ReactNode> & ReactPortalIterable<ReactNode> & Promise<AwaitedReactNode>ReactPortal & stringReactPortal & numberReactPortal & bigintReactPortal & falseReactPortal & trueReactPortal & ReactElement<unknown, stringJSXElementConstructor<any>>ReactPortal & Iterable<ReactNode>ReactPortal & Promise<AwaitedReactNode>Promise<AwaitedReactNode> & stringPromise<AwaitedReactNode> & numberPromise<AwaitedReactNode> & bigintPromise<AwaitedReactNode> & falsePromise<AwaitedReactNode> & truePromise<AwaitedReactNode> & ReactElement<unknown, stringJSXElementConstructor<any>>Promise<AwaitedReactNode> & Iterable<ReactNode>Promise<AwaitedReactNode> & ReactPortal | Contents of `InputLabelNext` component, if not set, label is not rendered. | ||
| labelRightSection | ReactNode | Adds a component to the right of the input at the label level. Useful for password strength. | ||
| max | stringnumberundefined | @platform web | ||
| maxLength | numberundefined | Maximum string length that the user can enter in UTF-16 code units | ||
| min | stringnumberundefined | @platform web | ||
| minLength | numberundefined | Maximum string length that the user can enter in UTF-16 code units @platform web | ||
| name | stringundefined | Html input name @platform web | ||
| onChange | ((value: string) => void)undefined | Trigger when input value is changing | ||
| onPress | 2 possibilities((event: GestureResponderEvent) => void)undefined | |||
| onReset | ((e: GestureResponderEvent) => void)undefined | |||
| placeholder | stringundefined | |||
| prefixPointerEvents | 5 possibilities"none""auto""box-none""box-only"undefined | Sets pointer-events styles on the `prefix` element, `none` by default | ||
| progress | booleanundefined | |||
| readonly | booleanundefined | Make input readonly | ||
| render | 2 possibilities((elements: { input: ReactNode; prefix?: ReactNode; suffix?: ReactNode; }, pseudoState: PseudoState) => ReactNode)undefined | Fully control how input, prefix and suffix are rendererd | ||
| renderPlaceholder | 2 possibilities((() => ReactNode) & (() => ReactNode)) | ((() => ReactNode) & (() => ReactNode))undefined | To render a custom placeholder view when the field is empty | ||
| required | booleanundefined | Determines whether the input should have `aria-required` attribute Adds required attribute to the input and a red asterisk on the right side of label, `false` by default | ||
| size | "sm""md"undefined | |||
| step | stringnumberundefined | @platform web | ||
| suffix | ReactNode | Content section rendered on the right side of the input | ||
| suffixPointerEvents | 5 possibilities"none""auto""box-none""box-only"undefined | Sets pointer-events styles on the `suffix` element, `none` by default | ||
| sx | PositionPropsundefined | Positioning properties | ||
| title | stringundefined | Html input title @platform web | ||
| type | HTMLInputTypeAttributeundefined | HTML input type @platform web | ||
| value | stringundefined | Control the input. |
Undocumented props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| autoComplete | any | |||
| autoCorrect | any | |||
| clearButtonMode | any | |||
| data-1p-ignore | any | |||
| data-lpignore | any | |||
| onBlur | any | |||
| onFocus | any | |||
| onKeyPress | any | |||
| onSubmitEditing | any | |||
| ref | any | |||
| returnKeyType | any | |||
| testID | any |
Style API
Use sx for one-off adjustments. It accepts these style keys:
Each can be overridden per breakpoint with: