Using Solid 2
Requirements
| Package | Required |
|---|---|
solid-js | >=2.0.0 <3 |
@solidjs/web | >=2.0.0 <3 |
@internationalized/date | 3.12.3, if you use DatePicker or DateInput |
Use a Solid 2 build toolchain: @solidjs/vite-plugin (or another Solid 2
compiler) with jsxImportSource set to @solidjs/web.
Solid 2 JSX
- Lowercase attributes. Use
tabindex,readonly,maxlength,colspan, andfor, nottabIndex,readOnly,maxLength,colSpan, orhtmlFor. Component props such asreadOnlyonField.RootorNumberInput.Rootkeep their names. classarrays and objects.classaccepts Solid 2's array and toggle object forms on every Lever UI part. There is noclassList.- No
on:,attr:,prop:, oruse:. Use camelCase handlers such asonClick. For listener options, add the listener from arefcallback. - ARIA booleans. A boolean attribute is present or absent, so
aria-expanded={false}removes the attribute. Write'true'or'false'. - Refs. A
refmay be an array of callbacks. Lever UI forwards every one. - Deferred writes. A signal read right after a write returns the old value
until the next flush. In tests, call
flush()before asserting.
<Spinner onClick={handle} tabindex={0} class={{ busy: busy() }} />
Composition: render
Parts accept a render prop beside as and asChild. render receives a
props function and the part's state accessor. Use one of as, asChild, or
render on a part.
<Accordion.Item
value="a"
render={(props, state) => <section {...props()} data-open={String(state().expanded)} />}
>
…
</Accordion.Item>
state is typed unknown. Narrow it before reading a field. Wrapper
types that drop the composition props must drop render too:
Omit<SwitchRootProps<'label'>, 'as' | 'asChild' | 'render'>.
Part attributes and IDs
Each part has one attribute named after the component and part, whose value is the part's scoped id.
[data-popover-trigger] {
}
Parts that nothing references, such as most roots, get no id. The ids
option only sets the IDs of referenced parts. Pass id to the part itself when
you need one. Style with the .leverui-<component>__<part> classes.
Overlay stacking
A z-index on overlay content cannot lift it above the page. For Popover, Menu,
Select, Combobox, HoverCard, Tooltip, DatePicker, and ColorPicker, set it on
the matching .leverui-<component>__positioner. For toasts, set it on
.leverui-toast__toaster. The positioner, and the dialog and drawer backdrop,
stack at calc(<layer z-index> + var(--layer-index)).
Utilities and types
createContextreturnsContext<Value | null>.nullmeans no provider. The lookup function returnsundefinedfor a loose context.Input'sdefaultValueaccepts what Solid 2'sinputaccepts.Icon'stitleacceptsfalse, as Solid 2 attributes do.
Server rendering
Use the Vite plugin's start option with ssr: true. The
server rendering guide has the setup and the rules for
hydration. Solid 2 writes an empty attribute as its bare name: data-disabled,
not data-disabled="". Browsers read both the same way.
Testing
Call
flush()fromsolid-jsafter changing a signal and before asserting.Configure testing-library to flush after events:
import { configure } from '@testing-library/dom'; import { flush } from 'solid-js'; configure({ eventWrapper(dispatch) { const result = dispatch(); flush(); return result; }, });Wait a microtask after rendering before asserting on machine effects, such as measured sizes or focus moves.