Skip to content

Commit 8751e78

Browse files
zernoniaclaude
andauthored
feat(elements): Calendar, RangeCalendar, date/time fields and pickers, Color families, NumberField, PinInput, Slider, Rating (#3080) (#3096)
* feat(elements): custom elements foundation for eight families (#3080) Add `reka-ui/elements`: a side-effect-free `defineRekaElements()` plus per-family helpers that register `<reka-<family>-<part>>` custom elements for Switch, Checkbox, Toggle, Tabs, Accordion, Collapsible, Dialog and Popover. Each element renders its part onto itself through a small custom renderer, inherits context from the nearest Reka element above it, maps props to attributes/properties and emits to cancelable CustomEvents. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(elements): add custom elements guide Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * chore(elements): add typesVersions entry and raise Dialog element size limit Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(elements): rework the element foundation after review (#3080) - Find parents over the Context Community Protocol (context-request / context-provider) instead of instanceof and whenDefined: synchronous moves rebind, undefined ancestors are skipped, late providers take their descendants over, and copies of the library interoperate. App ids come from a counter shared through Symbol.for. - Drop the data-reka-fragment sibling: root-level nodes stay detached, wrappers take the host's place, and form values go through ElementInternals (reset, state restore, fieldset disabled). - Own the attributes the part renders: consumer writes while mounted become the value given back. `disabled` follows the prop, follows HTML boolean semantics, and is reflected from the property. - Keep uncontrolled state across remounts, strip a cloned element's rendered state, make unrendered parts inert and hidden and leave their fields out of form data. - Only before-update-* and DOM-event emits are cancelable; add the `events` option and restrict `shadowRoot` to `{ mode }`. - Add defineAllRekaElements, element and JSX typings, and React 19/18 smoke tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(elements): document forms, ownership, typings and framework usage Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(elements): resolve portal targets up front and support shadow roots (#3080) Build on the Shadow DOM utilities from #3083. A portal element's target is resolved from where the element sits before its first render: its portal's own lookup runs from an anchor in the element's detached container, which sent content inside a shadow root to the document body and cost force-mounted portals an extra render. Parent lookup uses the shared `containsComposed`, so slotted elements are found too. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(elements): address the verification review of #3087 (#3080) - Mirror hidden fields' validity to ElementInternals (required is enforced) - Retarget portals when a consumer move changes their root node - Find late providers' orphans in nested shadow roots - Let a consumer `hidden` / `inert` take over from the unrendered state - Start over when the parent part unmounts; never carry an overlay's `open` - Warn instead of throwing when a part needs another copy's context - `el.disabled` reflects the attribute both ways and reads as a boolean - Add types-only `reka-ui/elements/global` and `reka-ui/elements/react` - Port the review repros into tests, with a Vue as-child group form test Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(elements): follow part `id` props from #3092 (#3080) Collapsible/Accordion/Popover/Tabs/Dialog parts now render the consumer's `id`. The clone test checks the copy against library-owned state (`data-state` and a generated id) instead, and the id tests assert the new behaviour. Raise the all-families size limit for the components' added props. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(elements): address CodeRabbit review of #3087 (#3080) - Reject uppercase tag prefixes up front (custom element names allow none) - Only treat a missing-injection error as "waiting for a parent"; log the rest - Guide: define portal families after React hydration; `.prop` needs `.camel` - Tests for each, including React 18/19 portal hydration and Vue bindings Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(Toggle): submit the value of a pressed Toggle with its form The hidden checkbox had `value` but never `checked`, so a named Toggle was always left out of its form's data, in Vue and as `<reka-toggle>` (also after a form-state restore). Bind `checked` like Checkbox, Switch and Radio do. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * ci(elements): give the browser tests the built dist (#3080) `copies.browser.test.ts` loads the built `reka-ui/elements` next to the source as a second copy of the library, and was skipped in CI for lack of a build. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(Toggle): leave a disabled Toggle out of its form Pass `disabled` to the hidden checkbox, as Checkbox, Switch and Radio do, so a pressed but disabled Toggle is not submitted, like a disabled native control. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * feat(elements): date, time and list attributes, input targets and slot props (#3080) Foundation for the date, color and numeric families: - attribute kinds `numbers` (`"20 80"`), `date`, `time`, `date-range` and `time-range` (ISO 8601 strings parsed with the global `Temporal`; invalid ones are ignored with a dev warning) - part hints `target: 'input' | 'svg'` (render onto a native child), `siblingsInside` (keep rendered siblings inside the element), and `asChild` / `formAssociated` for wrapping parts without those props - `el.slotProps` and a `slot-props-change` event expose a part's slot props - table semantics for calendar grid parts - a teleported host that reconnects inside its wrapper keeps its parent - date segments mounted after their root join keyboard navigation - DateField, TimeField and the range fields and PinInput pass `as` / `asChild` to their Primitive; RangeCalendarRoot renders its hidden heading after the slot; ColorSwatchPickerItemSwatch forwards its default slot Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * feat(elements): calendar, date, time, color and numeric families (#3080) Adds Calendar, RangeCalendar, DateField, DateRangeField, TimeField, TimeRangeField, DatePicker, DateRangePicker, ColorArea, ColorField, ColorSlider, ColorSwatch, ColorSwatchPicker, NumberField, PinInput, Slider and Rating as custom elements, with their typings, browser tests (keyboard, pointer, events, ARIA, forms, Shadow DOM, React 18/19), axe checks and the guide's sections on dates, colors and slot props. Size limits: runtime + Switch 13 KB, Dialog 23 KB, all families 100 KB. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(elements): stub ResizeObserver for the jsdom slider, allow time for the dist import (#3080) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(elements): resolve leftover merge conflict markers from the v3 merge (#3080) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(elements): keep time zone names whole when splitting a date range attribute (#3080) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(elements): address the review of the date, color and numeric families (#3080) - Date attributes: a calendar annotation (`2026-10-14[u-ca=japanese]`, what `toString()` prints for other calendars) parses as a plain date, not a zoned one; only a time zone annotation makes a `ZonedDateTime`. A space between date and time keeps the time. - Form state: Temporal model values are saved as ISO strings and read back through the attribute parsers, instead of being restored as plain strings that broke every date and time field. - A native `<input>` the part rendered onto gets its `value` / `checked` back when the part unmounts. - A consumer's move of a host that is away (teleported) is handled again: only a wrapper the part inserts around it counts as its own move. - `slotProps` is `undefined` while the part is not rendered (a closed date picker calendar), and the next render dispatches new ones. - Guide: the calendar example gives each grid its month's `value`, and the date field example renders a field that already rendered. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(elements): render calendar month and year views from their view element (#3080) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(elements): restore the axe test's ResizeObserver stub in an after-each hook (#3080) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 9dac419 commit 8751e78

23 files changed

Lines changed: 2393 additions & 38 deletions

‎docs/content/docs/guides/custom-elements.md‎

Lines changed: 127 additions & 7 deletions
Large diffs are not rendered by default.

‎docs/content/meta/ColorSwatchPickerItemSwatch.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
'required': false
2323
}
2424
]" />
25+
26+
<SlotsTable :data="[
27+
{
28+
'name': 'color',
29+
'description': '',
30+
'type': 'string'
31+
},
32+
{
33+
'name': 'alpha',
34+
'description': '',
35+
'type': 'number'
36+
}
37+
]" />
2538
</llm-exclude>
2639

2740
<llm-only>
@@ -34,4 +47,11 @@
3447
| `asChild` | Change the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | `boolean` | No | - |
3548
| `label` | Optional accessible label for the color. If omitted, the color name will be derived from the color value. | `string` | No | - |
3649

50+
**Slots**
51+
52+
| Name | Description | Type |
53+
| --- | --- | --- |
54+
| `color` | | `string` |
55+
| `alpha` | | `number` |
56+
3757
</llm-only>

‎packages/core/.size-limit.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@
5656
{
5757
"path": "dist/elements.js",
5858
"import": "{ defineRekaElements, switchElements }",
59-
"limit": "15 KB",
59+
"limit": "16 KB",
6060
"name": "Elements: runtime + Switch"
6161
},
6262
{
6363
"path": "dist/elements.js",
6464
"import": "{ defineRekaElements, dialogElements }",
65-
"limit": "25 KB",
65+
"limit": "27 KB",
6666
"name": "Elements: Dialog"
6767
},
6868
{
6969
"path": "dist/elements.js",
7070
"import": "{ defineRekaElements, rekaElementFamilies }",
71-
"limit": "140 KB",
71+
"limit": "190 KB",
7272
"name": "Elements: all supported families"
7373
},
7474
{

‎packages/core/src/ColorSwatchPicker/ColorSwatchPickerItemSwatch.vue‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ defineExpose(expose)
2222

2323
<template>
2424
<ColorSwatch
25+
v-slot="slotProps"
2526
:ref="forwardRef"
2627
v-bind="mergeProps(props, part.attrs.value)"
27-
/>
28+
>
29+
<!-- Forwarded, so `asChild` has a child to render as. -->
30+
<slot v-bind="slotProps" />
31+
</ColorSwatch>
2832
</template>

‎packages/core/src/DateField/DateFieldRoot.vue‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ defineExpose(mergeExpose(expose, {
258258
<Primitive
259259
v-bind="getRootAttrs()"
260260
ref="primitiveElement"
261+
:as="as"
262+
:as-child="asChild"
261263
@focusin="handleFocusin"
262264
@focusout="handleFocusout"
263265
>

‎packages/core/src/DateRangeField/DateRangeFieldRoot.vue‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ defineExpose(mergeExpose(expose, {
161161
<Primitive
162162
v-bind="mergeProps($attrs, root.attrs.value)"
163163
ref="primitiveElement"
164+
:as="as"
165+
:as-child="asChild"
164166
>
165167
<slot
166168
:model-value="modelValue"

‎packages/core/src/PinInput/PinInputRoot.vue‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ providePinInputRootContext(context)
126126
<Primitive
127127
v-bind="mergeProps($attrs, root.attrs.value)"
128128
:ref="forwardRef"
129+
:as="as"
130+
:as-child="asChild"
129131
>
130132
<slot :model-value="modelValue" />
131133

‎packages/core/src/RangeCalendar/RangeCalendarRoot.vue‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,6 @@ onMounted(() => {
309309
:as-child="asChild"
310310
v-bind="root.attrs.value"
311311
>
312-
<div
313-
style="border: 0px; clip: rect(0px, 0px, 0px, 0px); clip-path: inset(50%); height: 1px; margin: -1px; overflow: hidden; padding: 0px; position: absolute; white-space: nowrap; width: 1px;"
314-
>
315-
<div
316-
:id="headingId"
317-
role="heading"
318-
aria-level="2"
319-
>
320-
{{ fullCalendarLabel }}
321-
</div>
322-
</div>
323-
324312
<slot
325313
:date="placeholder"
326314
:grid="grid"
@@ -332,5 +320,17 @@ onMounted(() => {
332320
:view="view"
333321
:granularity="granularity"
334322
/>
323+
<!-- After the slot, as in `CalendarRoot`: with `asChild`, the root's attributes go to the first child. -->
324+
<div
325+
style="border: 0px; clip: rect(0px, 0px, 0px, 0px); clip-path: inset(50%); height: 1px; margin: -1px; overflow: hidden; padding: 0px; position: absolute; white-space: nowrap; width: 1px;"
326+
>
327+
<div
328+
:id="headingId"
329+
role="heading"
330+
aria-level="2"
331+
>
332+
{{ fullCalendarLabel }}
333+
</div>
334+
</div>
335335
</Primitive>
336336
</template>

‎packages/core/src/TimeField/TimeFieldRoot.vue‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ defineExpose(mergeExpose(expose, {
159159
<Primitive
160160
v-bind="mergeProps($attrs, root.attrs.value)"
161161
ref="primitiveElement"
162+
:as="as"
163+
:as-child="asChild"
162164
>
163165
<slot
164166
:model-value="modelValue"

‎packages/core/src/TimeRangeField/TimeRangeFieldRoot.vue‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ defineExpose(mergeExpose(expose, {
161161
<Primitive
162162
v-bind="mergeProps($attrs, root.attrs.value)"
163163
ref="primitiveElement"
164+
:as="as"
165+
:as-child="asChild"
164166
>
165167
<slot
166168
:model-value="modelValue"

0 commit comments

Comments
 (0)