Mixins / foldkit-mixins-ui

NumberField

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

export * as NumberField from './numberField.js'

In the guides

Members

NumberField.NumberFieldSlots

const · packages/mixins-ui/src/numberField.ts:26

const NumberFieldSlots: Slots.Contract<{ readonly input: Slot.UnnamedSlot<Capability.Capability<"Focusable", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly [Event.EventToken<"keydown">], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"disabled">], readonly Slot.RequirementName[], boolean>; readonly decrement: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly [Attr.AttrToken<"aria-label">, Attr.AttrToken<"disabled">], readonly Slot.RequirementName[], boolean>; readonly increment: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly [Event.EventToken<"click">], readonly [Attr.AttrToken<"aria-label">, Attr.AttrToken<"disabled">], readonly Slot.RequirementName[], boolean>; readonly description: 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 group: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly [], readonly [], readonly [], false>; readonly start: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Int …;

A number field, the APG's editable spinbutton and Zag's number input: a text field with role="spinbutton" that the arrows step, PageUp and PageDown step by a page, and Home and End take to the bounds, between a decrement and an increment button outside the tab order. The number is the application's: the view draws value and sends onChange with the next one, clamped and on the step; typed text commits on change (blur or Enter), and text that is no number sends the value back unchanged.

NumberField.NumberFieldView

interface · packages/mixins-ui/src/numberField.ts:58

interface NumberFieldView<Message> extends Adornments {
  readonly id: string
  readonly label: string
  readonly description?: string | undefined
  readonly value: Option.Option<number>
  readonly onChange: (value: Option.Option<number>) => NoInfer<Message>
  readonly min?: number | undefined
  readonly max?: number | undefined
  readonly step?: number | undefined
  readonly page?: number | undefined
  readonly disabled?: boolean | undefined
  readonly invalid?: boolean | undefined
  readonly readOnly?: boolean | undefined
  readonly words?: Partial<NumberFieldWords> | undefined
  readonly name?: string | undefined
  readonly required?: boolean | undefined
  readonly style?: NamedStyle<typeof NumberFieldSlots> | undefined
  readonly mixins?: MixinList<Message> | undefined
}

NumberField.NumberFieldWords

interface · packages/mixins-ui/src/numberField.ts:48

interface NumberFieldWords {
  readonly decrease: string
  readonly increase: string
}

NumberField.NumberText

type · packages/mixins-ui/src/numberField.ts:97

type NumberText =
  | {
      readonly locale?: string | undefined
      readonly format?: undefined
      readonly parse?: undefined
    }
  | {
      readonly locale?: undefined
      readonly format: (value: number) => string
      readonly parse: (text: string) => Option.Option<number>
    }

How the number reads in the field and to a screen reader, and how typed text is read back: the two together, so what the field draws is what it accepts. locale draws and reads that locale's marks (de-DE: 1.234,5); format with its parse is for anything else; with neither, String and a plain number (a lone comma reads as the decimal mark).

NumberField.parseNumber

function · packages/mixins-ui/src/numberField.ts:133

function parseNumber(text: string, locale?: string): Option.Option<number>

The number text reads as in locale, or none. The locale's group mark goes whatever spelling the runtime's ICU gives it (' or a typographic one, a space or a no-break one), its decimal mark becomes ., and a typed . stays a decimal point where the locale's decimal is not . and its group is not either: people type the dot. Without a locale the text is a plain number, with a lone comma as its decimal mark.

NumberField.settled

function · packages/mixins-ui/src/numberField.ts:162

function settled(
  value: number,
  bounds: {
    readonly min?: number | undefined
    readonly max?: number | undefined
    readonly step?: number | undefined
  },
): number

value within the bounds and on the step counted from min (or 0).

NumberField.view

function · packages/mixins-ui/src/numberField.ts:179

function view<Message>(
  options: NumberFieldView<Message> & NumberText,
  h: HtmlBuilder<Message>,
): Html

NumberField.words

const · packages/mixins-ui/src/numberField.ts:56

const words = { decrease, increase }

The defaults, in English.