Documentation
Form Controls
renderOption

renderOption

This an example of the default option rendering function. Based on that you can create your own renderOption function.

import { SelectOptionDefault } from './types'
 
const _renderOption = (option: SelectOptionDefault) => {
  return <span>{getOptionLabel(option)}</span>
}

Caveats

The props of renderOption carry className that has all interaction on hover and focus. You can either preserve this like in example or skip altogether if you want to have your own styles for things like selected, hover or disabled. Please refer to type definition to find out what you can base your styles on.

Component API

type of RenderOptionProps

PropDefaultDescription
key
string

Key of the option

tabIndex
number

Tab index of the option

aria-selected
boolean

Aria-selected attribute of the option

aria-disabled
boolean

Aria-disabled attribute of the option

aria-label
string

Aria-label attribute of the option

role
string

Role attribute of the option

className
string

Class name of the option

ref
(node: any) => void

ref passed to the option li tag. Used by @floating-ui/react

active
boolean

Is option being hovered or tabbed on?

selected
boolean

Is option currently selected?

disabled
boolean

Is option disabled?

label
string

Label of the option. Result of getOptionLabel docs.