Select

This component is work in progress and not yet available for use.

Displays a list of options for the user to pick from - triggered by a button.

Features

  • Can be controlled or uncontrolled.
  • Offers 2 positioning modes.
  • Supports items, labels, groups of items.
  • Focus is fully managed.
  • Full keyboard navigation.
  • Supports custom placeholder.
  • Typeahead support.
  • Supports Right to Left direction.

Installation

Install the component from your command line.

cargo add radix-yew-select

Anatomy

Import all parts and piece them together.

use radix_yew_switch::*;
use yew::prelude::*;

#[function_component]
fn Anatomy() -> Html {
    html! {
        <Select>
            <SelectTrigger>
                <SelectValue />
                <SelectIcon />
            </SelectTrigger>

            <SelectPortal>
                <SelectContent>
                    <SelectScrollUpButton />
                    <SelectViewport>
                        <SelectItem>
                            <SelectItemText />
                            <SelectItemIndicator />
                        </SelectItem>

                        <SelectGroup>
                            <SelectLabel />
                            <SelectItem>
                                <SelectItemText />
                                <SelectItemIndicator />
                            </SelectItem>
                        </SelectGroup>

                        <SelectSeparator />
                    </SelectViewport>
                    <SelectScrollDownButton />
                    <SelectArrow />
                </SelectContent>
            </SelectPortal>
        </Select>
    }
}

API Reference

TODO

Examples

TODO

Accessibility

Adheres to the ListBox WAI-ARIA design pattern.

See the W3C Select-Only Combobox example for more information.

Keyboard Interactions

KeyDescription
SpaceWhen focus is on SelectTrigger, opens the select and focuses the selected item.
When focus is on an item, selects the focused item.
EnterWhen focus is on SelectTrigger, opens the select and focuses the first item.
When focus is on an item, selects the focused item.
ArrowDownWhen focus is on SelectTrigger, opens the select.
When focus is on an item, moves focus to the next item.
ArrowUpWhen focus is on SelectTrigger, opens the select.
When focus is on an item, moves focus to the previous item.
EscCloses the select and moves focus to Select.Trigger.

Labelling

Use the Label component in order to offer a visual and accessible label for the select.

use radix_yew_label::*;
use radix_yew_switch::*;
use yew::prelude::*;

#[function_component]
fn Labelling() -> Html {
    html! {
        <>
            <Label>
                {"Country"}
                <Select>...</Select>
            </Label>

            // or

            <Label r#for="country">Country</Label>
            <Select>
                <SelectTrigger id="country">...</SelectTrigger>

                <SelectPortal>
                    <SelectContent>...</SelectContent>
                </SelectPortal>
            </Select>
        </>
    }
}

Custom APIs

TODO

See Also