Mixins / foldkit-mixins-ui

Combobox

namespace · packages/mixins-ui/src/combobox.ts:1

export * as Combobox from './combobox.js'

In the guides

Members

Combobox.ComboboxPreset

type · packages/mixins-ui/src/combobox/view.ts:161

type ComboboxPreset = Pick<
  ComboboxView<string, unknown, never>,
  | 'filter'
  | 'placeholder'
  | 'chips'
  | 'openOnFocus'
  | 'anchor'
  | 'words'
  | 'style'
> & {
  readonly clear?: true
  readonly mixins?: MixinList<never>
}

What a Combobox is given once: its look and each option that holds no Message, no drawing and nothing of one field's value.

Combobox.ComboboxSlots

const · packages/mixins-ui/src/combobox/slots.ts:27

const ComboboxSlots: Slots.Contract<{ readonly wrapper: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly inputWrapper: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly input: Slot.UnnamedSlot<Capability.Capability<"TextInput", readonly [Capability.Capability<"Focusable", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>]>, readonly [Event.EventToken<"input">, Event.EventToken<"keydown">, Event.EventToken<"blur">, Event.EventToken<"focus">], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-expanded">, Attr.AttrToken<"disabled">, Attr.AttrToken<"aria-disabled">], readonly Slot.RequirementName[], boolean>; readonly toggleButton: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly [Attr.AttrToken<"aria-expanded">, Attr.AttrToken<"disabled">, Attr.AttrToken<"aria-disabled">], readonly Slot.RequirementName[], boolean>; readonly backdrop: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Cap …;

Combobox is a nested Submodel: an input/inputWrapper pair with an optional toggleButton, plus a backdrop/items group with an item per entry (and group/heading/separator where the caller groups), so the resolver runs once per bundle and each base attribute passes through by identity. hiddenInputs are the form inputs submitted under formName: generated markup with no styling surface, passed through for the draw to place.

The input owns input/keydown/blur (and focus with openOnFocus); an item owns click while interactive; the toggle owns click while enabled. A Behavior adding its own handler to one of those is a conflict, not a second silent owner.

From chips on, the slots are this package's: the chosen values as chips in the field (the chips view input), the clear button (clearContent), the panel shown in the list's place while there are no items (empty), and an option's parts, which parts draws as Listbox's does, the typed text marked in its label (match) and what a row holds after its label (itemTrailing).

A module of its own, which the adapter re-exports: the Behaviors that attach to these slots are files of their own and read it at load.

Combobox.ComboboxView

interface · packages/mixins-ui/src/combobox/view.ts:25

interface ComboboxView<Item extends string, Value, Outer> {
  readonly model: UiCombobox.Model
  readonly onMessage: (message: UiCombobox.Message) => Outer
  readonly label: string
  readonly choice: Choice<Item, Value>
  readonly value: NoInfer<Value>
  readonly items?: ReadonlyArray<NoInfer<Item>> | undefined
  readonly filter?: ((label: string, typed: string) => boolean) | undefined
  readonly option?: ((item: NoInfer<Item>) => RowContent) | undefined
  readonly groupBy?: ((item: NoInfer<Item>) => string) | undefined
  readonly heading?: ((group: string) => Html) | undefined
  readonly placeholder?: string | undefined
  readonly empty?: Html | undefined
  readonly clear?:
    | true
    | {
        readonly content: Html
      }
    | undefined
  readonly chips?: boolean | undefined
  readonly buttonContent?: Html | undefined
  readonly disabled?: boolean | undefined
  readonly invalid?: boolean | undefined
  readonly readOnly?: boolean | undefined
  readonly name?: string | undefined
  readonly openOnFocus?: boolean | undefined
  readonly anchor?: AnchorConfig | undefined
  readonly words?: Partial<ComboboxWords> | undefined
  readonly style?: NamedStyle<typeof ComboboxSlots> | undefined
  readonly mixins?: MixinList<Outer> | undefined
}

Combobox.ComboboxWords

interface · packages/mixins-ui/src/combobox/words.ts:2

interface ComboboxWords {
  readonly clear: string
  readonly remove: string
}

The fixed text a Combobox says. Each is text; {label} is the chip's label.

Combobox.configure

function · packages/mixins-ui/src/combobox/view.ts:176

function configure<const Names extends string = never>(
  config: Presets<ComboboxPreset, Names>,
): {
  readonly view: <const Item extends string, Value, Outer>(
    options: ComboboxView<Item, Value, Outer> & PresetOption<Names>,
    h: HtmlBuilder<Outer>,
  ) => Html
}

The application's own Combobox: base for every use, presets chosen at a use with preset, and the call over both. mixins concatenate in that order and words merge word by word; any other option given at the call replaces the preset's.

Combobox.contains

function · packages/mixins-ui/src/combobox/filters.ts:7

function contains(label: string, typed: string): boolean

Rows whose label holds the typed text anywhere, ignoring case.

Combobox.draw

function · packages/mixins-ui/src/combobox.ts:205

function draw<Message>(
  resolved: ResolvedCombobox<Message>,
  h: HtmlBuilder<Message>,
): Html

Upstream's markup with this package's parts placed: the chips before the input and the clear button after it, in the field, and the empty panel after the list.

Combobox.fluid

const · packages/mixins-ui/src/combobox/fluid.ts:14

const fluid: readonly [Mixin<never>, Mixin<never>]

What moves the open panel's highlight and indicator: on its rows, the chosen row is measured (--fk-popup-chosen-*) and one highlight follows the pointer to the nearest row (--fk-popup-hover-*), and to the row the keys mark (data-active) while the pointer is away. A press in a gap is left alone: the field keeps focus. Pass them beside the style; until they run, each row marks itself.

Combobox.many

function · packages/mixins-ui/src/choice/many.ts:6

function many<const Item extends string>(
  items: ReadonlyArray<Item>,
): Choice<Item, ReadonlyArray<Item>>

Any number of items, in the order they were chosen: Selected flips one.

Combobox.one

function · packages/mixins-ui/src/choice/one.ts:5

function one<const Item extends string>(
  items: ReadonlyArray<Item>,
): SingleChoice<Item, Option.Option<Item>>

At most one of items: the value is an Option of an item.

Combobox.overlayBars

const · packages/mixins-ui/src/combobox/overlayBars.ts:11

const overlayBars: readonly [Mixin<never>]

What draws the open panel's scrollBar over its scroll (ScrollBars), in place of the browser's bar, on a pointer that can hover; a press on the bar leaves the field its focus. Pass it beside the style when the combobox scrolls (itemsScrollAttributes); without a scroll there is no bar.

Combobox.parts

function · packages/mixins-ui/src/combobox.ts:245

function parts<Message>(
  mixins: MixinList<Message>,
  context: ResolveContext<unknown, Message>,
): { option: (content: RowContent, query: string) => Html }

An option's content in the combobox's slots: its icon, its label with the typed query marked (or content of its own in the label's place), its description, what it holds after the label, and the check the chosen row shows. disabled is not drawn here: it is upstream's isItemDisabled. Pass the mixins the combobox's toView gets.

Combobox.resolve

function · packages/mixins-ui/src/combobox.ts:90

function resolve<Input, Message>(
  render: ComboboxRenderInfo,
  mixins: MixinList<Message>,
  context: ResolveContext<Input, Message>,
): ResolvedCombobox<Message>

Resolves the combobox's bundles (and every item's).

Combobox.ResolvedCombobox

type · packages/mixins-ui/src/combobox.ts:42

type ResolvedCombobox<Message> = Omit<
  ComboboxRenderInfo,
  | 'wrapper'
  | 'inputWrapper'
  | 'input'
  | 'toggleButton'
  | 'backdrop'
  | 'items'
  | 'scroll'
  | 'groups'
  | 'chips'
  | 'clearButton'
  | 'empty'
> & {
  readonly chips:
    | {
        readonly attributes: SlotAttributes<Message>
        readonly chips: ReadonlyArray<
          Part<Message> & {
            readonly label: string
            readonly remove: SlotAttributes<Message>
          }
        >
      }
    | undefined
  readonly clearButton:
    | (Part<Message> & {
        readonly content: Html
      })
    | undefined
  readonly empty:
    | (Part<Message> & {
        readonly content: Html
      })
    | undefined
  readonly wrapper: SlotAttributes<Message>
  readonly inputWrapper: SlotAttributes<Message>
  readonly input: SlotAttributes<Message>
  readonly toggleButton: ResolvedComboboxToggle<Message> | undefined
  readonly backdrop:
    | {
        key: string
        attributes: SlotAttributes<Message>
      }
    | undefined
  readonly items:
    | {
        key: string
        attributes: SlotAttributes<Message>
      }
    | undefined
  readonly scroll: SlotAttributes<Message> | undefined
  readonly rows: SlotAttributes<Message> | undefined
  readonly highlight: SlotAttributes<Message> | undefined
  readonly indicator: SlotAttributes<Message> | undefined
  readonly scrollBar: SlotAttributes<Message> | undefined
  readonly scrollThumb: SlotAttributes<Message> | undefined
  readonly groups: ReadonlyArray<ResolvedComboboxGroup<Message>>
}

Combobox.ResolvedComboboxGroup

type · packages/mixins-ui/src/combobox.ts:24

type ResolvedComboboxGroup<Message> = Omit<
  ComboboxGroupRender,
  'heading' | 'group' | 'separator' | 'items'
> & {
  readonly heading: ResolvedComboboxHeading<Message> | undefined
  readonly group:
    | {
        key: string
        attributes: SlotAttributes<Message>
      }
    | undefined
  readonly separator:
    | {
        key: string
        attributes: SlotAttributes<Message>
      }
    | undefined
  readonly items: ReadonlyArray<ResolvedComboboxItem<Message>>
}

Combobox.ResolvedComboboxHeading

type · packages/mixins-ui/src/combobox.ts:20

type ResolvedComboboxHeading<Message> = Omit<
  ComboboxHeadingRender,
  'attributes'
> & {
  readonly attributes: SlotAttributes<Message>
}

Combobox.ResolvedComboboxItem

type · packages/mixins-ui/src/combobox.ts:16

type ResolvedComboboxItem<Message> = Omit<ComboboxItemRender, 'attributes'> & {
  readonly attributes: SlotAttributes<Message>
}

Combobox.ResolvedComboboxToggle

type · packages/mixins-ui/src/combobox.ts:34

type ResolvedComboboxToggle<Message> = Readonly<{
  key: string
  attributes: SlotAttributes<Message>
  content: Html
}>

Combobox.startsWith

function · packages/mixins-ui/src/combobox/filters.ts:11

function startsWith(label: string, typed: string): boolean

Rows whose label starts with the typed text, ignoring case.

Combobox.text

function · packages/mixins-ui/src/choice/text.ts:9

function text<const Item extends string>(
  items: ReadonlyArray<Item>,
): SingleChoice<Item, string>

The typed text is the value, and items are suggestions for it: an autocomplete. Choosing an item writes it; typing writes what was typed, an item or not.

Combobox.toView

function · packages/mixins-ui/src/combobox.ts:260

function toView<Message>(
  mixins: MixinList<Message>,
  context: ResolveContext<unknown, Message>,
  drawResolved?: (resolved: ResolvedCombobox<Message>) => Html,
): (render: ComboboxRenderInfo) => Html

The combobox's toView: draw receives its bundles with mixins applied. Without one, it draws upstream's markup from them.

Combobox.view

function · packages/mixins-ui/src/combobox/view.ts:82

function view<const Item extends string, Value, Outer>(
  options: ComboboxView<Item, Value, Outer>,
  h: HtmlBuilder<Outer>,
): Html

A Combobox: a text field over a list of rows, the chosen ones marked. The value is the application's: it is passed at every draw, and what the reader chooses is reported by the state (Bundles.Combobox's ChoiceChange) for the application to fold through the same choice.

Combobox.words

const · packages/mixins-ui/src/combobox/words.ts:10

const words = { clear, remove }

The words a Combobox uses when none are given.