Kobalte UI Toolkit

repository·main·Indexed 23 days ago

https://github.com/kobaltedev/kobalte

An accessible, unstyled UI toolkit for building design systems and web applications with SolidJS. It provides low-level components and primitives that implement WAI-ARIA Authoring Practices. The ecosystem includes @kobalte/core for components, @kobalte/tailwindcss for state-based styling modifiers, and @kobalte/vanilla-extract for CSS-in-JS state styling.

Tokens
118.6K
Snippets
265
Records
521
Agent score
81%

What's inside Kobalte

  1. Overview of Kobalte

    main
    Kobalte is a UI toolkit designed for building accessible web applications and design systems using SolidJS. It provides unstyled components and primitives that focus on accessibility, allowing developers to apply their own custom styling.
  2. Introduction to Kobalte

    main

    Kobalte is a UI toolkit designed for building accessible web applications and design systems using SolidJS. It provides low-level UI components and primitives that serve as a foundation for custom design systems.

    Core Principles

    • Accessible: Components implement WAI-ARIA Authoring Practices by default. Kobalte manages complex accessibility requirements such as ARIA attributes, focus management, and keyboard navigation automatically.
    • Composable: The toolkit offers granular access to component parts. This allows you to wrap components and inject your own event listeners, props, and custom logic.
    • Unstyled: Kobalte follows a
  3. Combobox features and accessibility

    main

    The Kobalte Combobox implements the WAI ARIA Combobox design pattern and includes the following capabilities:

    • Selection Modes: Supports both single and multiple selection.
    • Filtering: Users can filter the list of options by typing in the input.
    • Accessibility:
      • Full support for labels, descriptions, and error messages linked via ARIA.
      • Custom localized announcements for focusing, filtering, and selection (using ARIA live regions) to mitigate VoiceOver bugs.
      • Browser autofill integration via a hidden native <select> element.
    • Keyboard Navigation: Supports opening the listbox via arrow keys and automatic focus management for the first/last items.
    • Structure: Supports items, item groups (Combobox.Section), and custom placeholders.
  4. Key features of the Select component

    main

    The Select component provides several built-in capabilities:

    • Accessibility: Implements the WAI ARIA Listbox pattern, including labeling, descriptions, and error message linking via ARIA.
    • Selection Modes: Supports both single and multiple selection.
    • Keyboard Navigation: Supports opening via arrow keys, automatic focus management for the first/last items, and typeahead selection.
    • Form Integration: Integrates with browser autofill via a hidden native <select> element.
    • Flexible Content: Supports disabled options, item groups (Select.Section), custom placeholders, and both controlled and uncontrolled states.
  5. How Breadcrumbs and their sub-components work together

    main

    Breadcrumbs provide navigational context using a hierarchy of links. The component structure follows a specific anatomy to ensure proper ARIA semantics:

    • Breadcrumbs (or Root): The root container that renders a <nav> element. It provides the landmark navigation context.
    • ol: A native HTML ordered list used to contain the breadcrumb items.
    • li: A native HTML list item that wraps a link and a separator.
    • Breadcrumbs.Link: The interactive element (renders an <a> by default) representing a step in the hierarchy.
    • Breadcrumbs.Separator: A visual element (renders a <span> by default) between items. It is hidden from screen readers to avoid noise.

    Note: You can use the separator prop on the root Breadcrumbs component to provide a default visual separator for all instances.

    <Breadcrumbs>
    	<ol>
    		<li>
    			<Breadcrumbs.Link />
    			<Breadcrumbs.Separator />
    		</li>
    	</ol>
    </Breadcrumbs>
  6. Understand the anatomy of the Select component

    main

    The Select component is composed of several parts that work together to implement the WAI ARIA Listbox pattern.

    Core Structure

    • Select: The root container.
    • Select.Trigger: The button that opens the select.
    • Select.Value: Displays the currently selected value.
    • Select.Portal: Renders the dropdown content into the body to avoid clipping issues.
    • Select.Content: The container for the dropdown content.
    • Select.Listbox: The container for the list of items.
    • Select.Item: An individual selectable option.

    Accessibility & Feedback

    • Select.Label: Provides an accessible label.
    • Select.Description: Provides additional context/information.
    • Select.ErrorMessage: Displays validation error messages.
    • Select.ItemLabel: The accessible name for an item.
    • Select.ItemDescription: An optional description for an item.
    • Select.ItemIndicator: A visual indicator (like a checkmark) for the selected item.

    Visual Elements

    • Select.Icon: A visual affordance (like a chevron) in the trigger.
    • Select.Arrow: An optional arrow element near the content.
    • Select.Section: Used for rendering labels for option groups (not focusable).

    Basic Composition Example

    <Select>
    	<Select.Label />
    	<Select.Trigger>
    		<Select.Value />
    		<Select.Icon />
    	</Select.Trigger>
    	<Select.Description />
    	<Select.ErrorMessage />
    
    	<Select.Portal>
    		<Select.Content>
    			<Select.Arrow />
    			<Select.Listbox />
    		</Select.Content>
    	</Select.Portal>
    </Select>
  7. How ColorArea components are composed

    main

    A ColorArea is built using a specific anatomy of sub-components. You are responsible for rendering these to create the visual interface:

    • ColorArea: The root container.
    • ColorArea.Background: The visual representation of the color range.
    • ColorArea.Thumb: The indicator of the current value.
    • ColorArea.HiddenInputX: A visually hidden native input for the horizontal axis.
    • ColorArea.HiddenInputY: A visually hidden native input for the vertical axis.
    • ColorArea.Label: Provides information/labeling for the component.

    Note: ColorArea.HiddenInputX and ColorArea.HiddenInputY are placed inside the ColorArea.Thumb to support touch screen readers.

    <ColorArea>
      <ColorArea.Label />
      <ColorArea.Background>
        <ColorArea.Thumb>
          <ColorArea.HiddenInputX />
          <ColorArea.HiddenInputY />
        </ColorArea.Thumb>
      </ColorArea.Background>
    </ColorArea>
  8. Style component states using data attributes

    main

    Kobalte automatically attaches data-* attributes to components and their parts to represent their current state. You can target these states in your CSS using attribute selectors.

    Common examples include:

    • data-expanded: When a component (like a Popover) is expanded.
    • data-disabled: When a component is disabled.
    • data-checked, data-selected, data-pressed, etc.
  9. How Dialog components work together

    main

    A Dialog is composed of several parts that manage the lifecycle, accessibility, and rendering of a modal window. The standard anatomy follows this structure:

    • Dialog (or Root): The top-level container managing the open state.
    • Dialog.Trigger: The element (defaults to a button) that opens the dialog.
    • Dialog.Portal: Renders the dialog children into the body to avoid z-index or nesting issues.
    • Dialog.Overlay: A background layer that covers the rest of the view.
    • Dialog.Content: The main container for the dialog's content.
    • Dialog.CloseButton: A button to close the dialog.
    • Dialog.Title: An accessible heading (defaults to h2) for screen readers.
    • Dialog.Description: An optional accessible description (defaults to p) for screen readers.
    <Dialog>
    	<Dialog.Trigger />
    	<Dialog.Portal>
    		<Dialog.Overlay />
    		<Dialog.Content>
    			<Dialog.CloseButton />
    			<Dialog.Title />
    			<Dialog.Description />
    		</Dialog.Content>
    	</Dialog.Portal>
    </Dialog>
    <Dialog>
    	<Dialog.Trigger />
    	<Dialog.Portal>
    		<Dialog.Overlay />
    		<Dialog.Content>
    			<Dialog.CloseButton />
    			<Dialog.Title />
    			<Dialog.Description />
    		</Dialog.Content>
    	</Dialog.Portal>
    </Dialog>
  10. How Accordion components work together

    main

    An Accordion is composed of several parts that follow the WAI ARIA Accordion pattern. The structure requires nesting a Trigger inside a Header, and the Header and Content must be children of an Item.

    • Accordion: The root container.
    • Accordion.Item: A collapsible section.
    • Accordion.Header: A wrapper for the trigger, typically rendered as a heading level (use the as prop to change the heading level).
    • Accordion.Trigger: The interactive element that toggles the item state.
    • Accordion.Content: The container for the content revealed when expanded.
    <Accordion>
    	<Accordion.Item>
    		<Accordion.Header>
    			<Accordion.Trigger />
    		</Accordion.Header>
    		<Accordion.Content />
    	</Accordion.Item>
    </Accordion>
  11. How ToggleGroup works

    main

    A ToggleGroup is a set of two-state buttons that can be toggled on (pressed) or off (not pressed). It consists of a root container (ToggleGroup) and individual toggle buttons (ToggleGroup.Item).

    It supports both horizontal and vertical orientations and provides built-in keyboard support for navigation and activation.

    <ToggleGroup>
    	<ToggleGroup.Item value="item-1" />
    </ToggleGroup>
    <ToggleGroup>
    	<ToggleGroup.Item />
    </ToggleGroup>