Components
Toolbar
A container for grouping a set of buttons and controls.
Usage guidelines#
To ensure that toolbars are accessible and helpful, follow these guidelines:
- Use inputs sparingly: Left and right arrow keys are used to both move the text insertion cursor in an input, and to navigate among controls in horizontal toolbars. When using an input in a horizontal toolbar, use only one and place it as the last element of the toolbar.
Anatomy#
Import the component and assemble its parts:
import { Toolbar } from '@egoist/solid-base/toolbar';
<Toolbar.Root>
<Toolbar.Button />
<Toolbar.Link />
<Toolbar.Separator />
<Toolbar.Group>
<Toolbar.Button />
<Toolbar.Button />
</Toolbar.Group>
<Toolbar.Input />
</Toolbar.Root>;Examples#
Using with other components#
Use the render prop to combine a toolbar part with a part from another component into a single
element. The element joins the toolbar's keyboard navigation and keeps the behavior of the other
part.
<Toolbar.Root>
<Menu.Root>
<Toolbar.Button render={(props) => <Menu.Trigger {...props} />} />
<Menu.Portal>{/* Compose the rest of the menu */}</Menu.Portal>
</Menu.Root>
</Toolbar.Root>- Popups with a trigger, such as Alert Dialog, Dialog, Drawer, Menu, Popover, and Select:
render the trigger from the
renderfunction of<Toolbar.Button>, as shown above. Setdisabledon<Toolbar.Button>rather than on the trigger, so the button stays in the toolbar's keyboard navigation. - Tooltip: render
<Toolbar.Button>from therenderfunction of<Tooltip.Trigger>instead:<Tooltip.Trigger render={(props) => <Toolbar.Button {...props} />} />. - Number Field: render
<NumberField.Input>from therenderfunction of<Toolbar.Input>, and keep it inside<NumberField.Root>and<NumberField.Group>with the increment and decrement buttons.
See how props are merged for how the two parts combine.
API reference#
<Toolbar.Root>
A container for grouping a set of controls, such as buttons, toggle groups, or menus. Renders a <div> element.
disabledboolean—orientationToolbarRoot.Orientation'horizontal'The orientation of the toolbar.
loopFocusbooleantrueIf true, using keyboard navigation will wrap focus to the other end of the toolbar once the end is reached.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-disabledPresent when the toolbar is disabled.
data-orientationIndicates the orientation of the toolbar.
<Toolbar.Separator>
A separator element accessible to screen readers. Renders a <div> element.
orientationOrientation'horizontal'The orientation of the separator. Defaults to the opposite of the toolbar's orientation, so a horizontal toolbar renders vertical separators.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-orientationIndicates the orientation of the separator, which is perpendicular to the toolbar.
<Toolbar.Group>
Groups several toolbar items or toggles. Renders a <div> element.
disabledbooleanfalseWhen true all toolbar items in the group are disabled.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-disabledPresent when the group is disabled.
data-orientationIndicates the orientation of the toolbar.
<Toolbar.Button>
A button that can be used as-is or as a trigger for other components. Renders a <button> element.
disabledbooleanfalseWhen true the item is disabled.
focusableWhenDisabledbooleantrueWhen true the item remains focusable when disabled.
nativeButtonbooleantrueWhether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-disabledPresent when the button is disabled.
data-orientationIndicates the orientation of the toolbar.
data-focusablePresent when the button remains focusable when disabled.
<Toolbar.Link>
A link component. Renders an <a> element.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-orientationIndicates the orientation of the toolbar.
<Toolbar.Input>
A native input element that integrates with Toolbar keyboard navigation. Renders an <input> element.
disabledbooleanfalseWhen true the item is disabled.
focusableWhenDisabledbooleantrueWhen true the item remains focusable when disabled.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-disabledPresent when the input is disabled.
data-orientationIndicates the orientation of the toolbar.
data-focusablePresent when the input remains focusable when disabled.