ChoicesWidget
This is a React component

Source
import { ChoicesWidget } from "@prestojs/ui-antd";
ChoicesWidget(props)

Render a list of choices.

The specific widget chosen is one of

  • SelectAsyncChoicesWidget - when asyncChoices is provided. widgetType is ignored in this case.
  • SelectChoicesWidget - when widgetType="select" or widgetType is not specified and there is more than 3 choices.
  • RadioChoicesWidget - when widgetType="radio" or multiple={false} and widgetType is not specified and there is 3 or fewer choices.
  • CheckboxChoicesWidget - when widgetType="checkbox" or multiple={true} and widgetType is not specified and there is 3 or fewer choices.
ParameterTypeDescription
*props

Any additional props are passed through to the specify widget

*props.input
InputProps

The input props for the widget. This should include, at minimum:

  • onChange
  • value

Can also include

  • name
  • onBlur
  • onFocus
  • type
  • checked
  • multiple
*props.choicesMap|[(RawValue|RawValue[]), string][]

The choices to render. This can be a Map of value to label or an array of 2-element arrays [value, label].

props.multipleboolean

Whether multiple values are accepted

props.widgetType"select"|"checkbox"|"radio"

Choices are rendered as either SelectChoicesWidget, RadioChoicesWidget (only if multiple=false) or CheckboxChoicesWidget (only if multiple=true) Specify select, 'radio', or checkboxto choose one of these or leave blank to select based on number of choices (if > 3 defaults to 'select' otherwise 'checkbox' or 'radio' depending on value ofmultiple`).

Examples

Basic Usage

When the number of choices is small (<=3) the default is a radio widget, otherwise it is a select widget. You can specify the type to use with widgetType.

Any extra props are passed through to the underlying component (eg. showSearch in the last example)

Multiple selection

Pass multiple through to allow selection of multiple values. In this case the value will be an array.

When the number of choices is small (<=3) the default is a checkbox widget, otherwise it is a select widget. You can specify the type to use with widgetType.

Any extra props are passed through to the underlying component (eg. showSearch in the last example)