Atomic slot contracts
An adapter can implement a stable atomic slot to own the whole interaction of one control. This page
lists, for each slot, the exact props type, the root element, the pt parts, whether a ref is
forwarded and which behavior stays in Components. It is generated from the profiles that
@cratis/components.conformance runs against a declared slot, so it describes what is tested. See
Primitive adaptation profile for how a library
declares an atomic slot.
datatables.paginator
Section titled “datatables.paginator”| Contract | Value |
|---|---|
| Props | TablePaginatorProps |
| Root element | <div> matching [role="navigation"] |
| Parts | root, range, info, pages, page, ellipsis, first, previous, next, last |
| Ref | None; the slot does not forward a ref |
Components owns:
- The props contract: zero-based
page,pageCount, zero-basedonPageChangeand the optional range and label props - The paging state that supplies those props
- The built-in paginator, used whenever the slot is not declared
The adapter owns:
- The navigation controls, their keyboard activation and their focus behavior
- Calling
onPageChangewith the zero-based target page, converting at the boundary when the design system counts from one
import type { TablePaginatorProps } from '@cratis/components/DataTables';import type { CratisAtomicSlotMap } from '@cratis/components/renderer';
const ExamplePaginator = ({ page, pageCount, onPageChange, pt }: TablePaginatorProps) => ( <div {...pt?.root} role='navigation' aria-label='Pagination' data-cratis-part='root'> <button type='button' aria-label='Previous page' disabled={page === 0} data-cratis-part='previous' onClick={() => onPageChange(page - 1)} > Previous </button> <span {...pt?.info} data-cratis-part='info'> {page + 1} / {pageCount} </span> <button type='button' aria-label='Next page' disabled={page >= pageCount - 1} data-cratis-part='next' onClick={() => onPageChange(page + 1)} > Next </button> </div>);
export const atomicSlots = { 'datatables.paginator': { mode: 'atomic', fidelity: 'native', render: ExamplePaginator },} satisfies CratisAtomicSlotMap;common.tooltip
Section titled “common.tooltip”| Contract | Value |
|---|---|
| Props | TooltipProps |
| Root element | <button> matching [data-cratis-part="trigger"] |
| Parts | None in pt |
| Ref | None; the slot does not forward a ref |
Components owns:
- The props contract: non-interactive
content,position,disabled,classNameand exactly one focusable trigger child - The overlay host and overlay container that the popup is bound to, read through
unstable_useOverlayHost()andunstable_useOverlayEnvironment()
The adapter owns:
- The trigger and popup parts, and describing the trigger with
aria-describedbyonly - Opening on hover and keyboard focus, and closing on blur and Escape
- Closing immediately when the overlay host closes, unmounts or changes
import { cloneElement, useId, useState } from 'react';import type { HTMLAttributes, ReactElement, SyntheticEvent } from 'react';import type { TooltipProps } from '@cratis/components/Common';import type { CratisAtomicSlotMap } from '@cratis/components/renderer';
type Trigger = TooltipProps['children']['props'] & HTMLAttributes<HTMLElement>;
// Runs the trigger's own handler first, so the tooltip never replaces behavior the host attached.const chain = <E extends SyntheticEvent>(own: ((event: E) => void) | undefined, next: (event: E) => void) => (event: E) => { own?.(event); next(event); };
const ExampleTooltip = ({ content, disabled, children }: TooltipProps) => { const [open, setOpen] = useState(false); const popupId = useId(); if (disabled || !content) { return children; } const trigger = children as ReactElement<Trigger>; const own = trigger.props; const describedBy = [own['aria-describedby'], open ? popupId : undefined].filter(Boolean).join(' '); return ( <> {cloneElement(trigger, { 'data-cratis-part': own['data-cratis-part'] ?? 'trigger', 'aria-describedby': describedBy || undefined, onFocus: chain(own.onFocus, () => setOpen(true)), onBlur: chain(own.onBlur, () => setOpen(false)), onMouseEnter: chain(own.onMouseEnter, () => setOpen(true)), onMouseLeave: chain(own.onMouseLeave, () => setOpen(false)), onKeyDown: chain(own.onKeyDown, (event) => { if (event.key === 'Escape') { setOpen(false); } }), })} {open && ( <div id={popupId} role='tooltip' data-cratis-part='popup' data-open> {content} </div> )} </> );};
export const atomicSlots = { 'common.tooltip': { mode: 'atomic', fidelity: 'native', render: ExampleTooltip },} satisfies CratisAtomicSlotMap;dropdown.select
Section titled “dropdown.select”| Contract | Value |
|---|---|
| Props | DropdownProps<unknown> |
| Root element | <button> matching [data-cratis-part="trigger"] |
| Parts | root, value, filter, trigger, clear, popover, listbox, option, multiple, indicator |
| Ref | None; the slot does not forward a ref |
Components owns:
- The props contract:
value,options,onChangeand themultiple,filterandshowClearmodes - The overlay container the popover renders into
The adapter owns:
- The trigger, filter input, listbox and options, with one keyboard and focus owner
- Opening, arrow-key and Enter selection, and Escape to close
- Calling
onChangeonce per user selection withsource: 'user'and the native event
import { useState } from 'react';import type { KeyboardEvent } from 'react';import type { DropdownProps } from '@cratis/components/Dropdown';import type { CratisAtomicSlotMap } from '@cratis/components/renderer';
const read = (option: unknown, key?: string) => (key ? (option as Record<string, unknown>)[key] : option);const displayValue = (value: unknown, fallback = '') => String(value ?? fallback);
const ExampleSelect = ({ name, value, options = [], optionLabel, optionValue, disabled, onChange, pt }: DropdownProps<unknown>) => { const [open, setOpen] = useState(false); const [active, setActive] = useState(0); const choose = (option: unknown, nativeEvent: Event) => { onChange?.(read(option, optionValue), { source: 'user', nativeEvent }); setOpen(false); }; const move = (event: KeyboardEvent<HTMLButtonElement>) => { if (event.key === 'ArrowDown' || event.key === 'ArrowUp') { event.preventDefault(); setOpen(true); setActive((active + (event.key === 'ArrowDown' ? 1 : options.length - 1)) % options.length); } else if (event.key === 'Escape') { setOpen(false); } else if (event.key === 'Enter' && open) { event.preventDefault(); choose(options[active], event.nativeEvent); } }; return ( <div {...pt?.root} data-cratis-part='root'> <input type='hidden' name={name} value={displayValue(value)} /> <button type='button' aria-haspopup='listbox' aria-expanded={open} disabled={disabled} data-cratis-part='trigger' onClick={() => setOpen(!open)} onKeyDown={move} > {displayValue(value, 'Choose')} </button> {open && ( <ul role='listbox' data-cratis-part='listbox'> {options.map((option, index) => ( <li key={index} role='option' aria-selected={index === active} data-cratis-part='option' onClick={(event) => choose(option, event.nativeEvent)} > {String(read(option, optionLabel))} </li> ))} </ul> )} </div> );};
export const atomicSlots = { 'dropdown.select': { mode: 'atomic', fidelity: 'native', render: ExampleSelect },} satisfies CratisAtomicSlotMap;display.datePicker
Section titled “display.datePicker”| Contract | Value |
|---|---|
| Props | DatePickerInputProps |
| Root element | <div> matching [data-cratis-part="group"] |
| Parts | root, group, input, segment, placeholder, trigger, popover, dialog, calendar, header, previous, heading, next, grid, cell, buttonBar, today, clear |
| Ref | None; the slot does not forward a ref |
Components owns:
- The props contract: a
Dateornullvalue,minDate,maxDate,disabled,readOnlyandinvalid - The overlay container the popover renders into
The adapter owns:
- The segmented input and the calendar popover, with one keyboard and focus owner
- Calling
onChangeonce per user selection withsource: 'user'and the native event - Keeping the value type of its calendar library inside the adapter
import { useRef, useState } from 'react';import type { DatePickerInputProps } from '@cratis/components/Common';import type { CratisAtomicSlotMap } from '@cratis/components/renderer';
const ExampleDatePicker = ({ disabled, onChange, pt }: DatePickerInputProps) => { const [open, setOpen] = useState(false); const trigger = useRef<HTMLButtonElement>(null); return ( <div {...pt?.group} role='group' data-cratis-part='group' onKeyDown={(event) => { if (event.key === 'Escape') { setOpen(false); trigger.current?.focus(); } }} > <input {...pt?.input} disabled={disabled} data-cratis-part='input' /> <button ref={trigger} type='button' aria-label='Open calendar' aria-expanded={open} disabled={disabled} data-cratis-part='trigger' onClick={() => setOpen(!open)} /> {open && ( <div role='dialog' aria-label='Calendar' data-cratis-part='calendar'> <button type='button' data-cratis-part='today' onClick={(event) => { onChange(new Date(), { source: 'user', nativeEvent: event.nativeEvent }); setOpen(false); }} > Today </button> </div> )} </div> );};
export const atomicSlots = { 'display.datePicker': { mode: 'atomic', fidelity: 'native', render: ExampleDatePicker },} satisfies CratisAtomicSlotMap;dialogs.dialog
Section titled “dialogs.dialog”| Contract | Value |
|---|---|
| Props | CratisDialogSlotProps |
| Root element | <section> matching [role="dialog"], or a platform <dialog> |
| Parts | backdrop, positioner, root, header, title, subtitle, headerActions, close, content, footer, confirm, cancel. A platform <dialog> owns backdrop and positioner, so those two parts then have no element |
| Ref | None; the slot does not forward a ref |
Components owns:
- The dialog stack tier and z-index, and the
DialogResultflow - The typed footer and its buttons, the header actions, busy and validity state, and the announcement live region
- Initial focus, and the overlay environment that descendants portal into
The adapter owns:
- The modal shell: focus trap, Escape, outside press, scroll lock and focus restoration
- The header, title, subtitle and close button, rendered from the props and the
hostprop
import type { HTMLAttributes } from 'react';import type { CratisDialogSlotProps } from '@cratis/components/Dialogs';import type { CratisAtomicSlotMap } from '@cratis/components/renderer';
const ExampleDialog = ({ title, pt, host }: CratisDialogSlotProps) => ( <dialog {...(pt?.root as HTMLAttributes<HTMLDialogElement> | undefined)} open aria-labelledby={`${host.id}-title`} data-cratis-part='root' data-open onCancel={(event) => { event.preventDefault(); host.dismiss('escape'); }} > <h2 id={`${host.id}-title`} ref={host.titleRef} data-cratis-part='title'> {title} </h2> <button type='button' aria-label={host.closeAriaLabel} data-cratis-part='close' onClick={() => host.dismiss('closeButton')} > {host.closeIcon} </button> {host.content} {host.footer} <div ref={host.registerOverlayContainer} /> </dialog>);
export const atomicSlots = { 'dialogs.dialog': { mode: 'atomic', fidelity: 'native', render: ExampleDialog },} satisfies CratisAtomicSlotMap;common.numberInput
Section titled “common.numberInput”| Contract | Value |
|---|---|
| Props | NumericInputProps |
| Root element | <input> matching input[type="number"] |
| Parts | root |
| Ref | Forwards a ref to the root element |
Components owns:
- The props contract: a controlled numeric
value,invalid, native input attributes andonChange - Converting an
undefinedchange into the command value
The adapter owns:
- The native number input and its typing interaction
- Reporting the next number, or
undefinedwhen the input is empty or not a valid number
import { forwardRef } from 'react';import type { NumericInputProps } from '@cratis/components/Common';import type { CratisAtomicSlotMap } from '@cratis/components/renderer';
const ExampleNumberInput = forwardRef<HTMLInputElement, NumericInputProps>( function ExampleNumberInput({ value, invalid, onChange, pt, ...inputProps }, ref) { return ( <input {...inputProps} {...pt?.root} ref={ref} type='number' value={value ?? ''} aria-invalid={invalid || undefined} data-cratis-part='root' onChange={(event) => { const next = event.currentTarget.valueAsNumber; onChange?.(Number.isNaN(next) ? undefined : next); }} /> ); },);
export const atomicSlots = { 'common.numberInput': { mode: 'atomic', fidelity: 'native', render: ExampleNumberInput },} satisfies CratisAtomicSlotMap;