Files
maoyingjie 1b972a78ba feat(collection): add optional filtering and virtual focus for composite pickers
ComboBox and Autocomplete need two capabilities the collection protocol did not
express: filtering a collection by an external input value, and keeping DOM focus
in the composite's input while an active option is tracked for
aria-activedescendant.

Both are opt-in members on CollectionOwner plus optionId/reveal on the owned
collection. Standalone ListBox and Select provide none of them and keep their
previous behaviour: DOM focus still moves into the list, one roving tab stop, no
row filtering.

Filtered rows stay mounted with data-filtered (display:none) so their text and
accepted selection survive; only display, aria positions and keyboard navigation
see the visible subset. Under virtual focus the list never takes DOM focus,
never exposes a roving tab stop, and leaves keyboard handling to the composite;
reveal() scrolls a virtualized window and waits for the row to mount before the
composite reads its id.

Includes the playground verification page, a ten-case suite and the B02a section
of the migration report.
2026-10-25 14:53:49 +08:00

128 lines
3.1 KiB
CSS

/* Adapted from HeroUI ce90ea3. Apache-2.0; see third-party/HEROUI-LICENSE. */
/* ==========================================================================
Base list-box item styles
========================================================================== */
/* Owner-filtered rows stay mounted (text and selection survive) but leave
display and keyboard navigation. */
.hv-list-box-item[data-filtered="true"] {
display: none;
}
.hv-list-box-item {
@apply relative flex min-h-9 w-full items-center justify-start gap-3 rounded-2xl px-2 py-1.5 outline-none no-highlight;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
transform 250ms var(--ease-out-quart),
box-shadow 150ms var(--ease-out);
@apply motion-reduce:transition-none;
/* Cursor */
cursor: var(--cursor-interactive);
[data-slot="label"] {
@apply pointer-events-none w-fit select-none;
}
[data-slot="description"] {
@apply pointer-events-none text-wrap select-none;
}
/* Add inline-end padding when indicator is present */
&:has(.hv-list-box-item__indicator) {
@apply pe-7;
}
/* Focus visible state (keyboard focus only).
React Aria always sets data-focused when it owns the item, so the native
fallback is scoped to consumers rendering this class outside React Aria. */
&:focus-visible:not([data-focused]),
&[data-focus-visible="true"] {
@apply status-focused;
}
/* Focus state */
&:focus,
&[data-focus="true"] {
}
/* Pressed state */
&:active,
&[data-pressed="true"] {
transform: scale(0.98);
}
/* Hover state */
@media (hover: hover) {
&:hover,
&[data-hovered="true"] {
@apply bg-default;
}
}
/* Selected state */
&[aria-selected="true"],
&[data-selected="true"] {
}
/* Disabled state */
&[data-disabled="true"] {
@apply status-disabled;
}
}
/* ==========================================================================
List-box item indicator
========================================================================== */
.hv-list-box-item__indicator {
@apply absolute end-2 top-1/2 flex size-4 shrink-0 -translate-y-1/2 items-center justify-center text-default-foreground;
/**
* Transitions
*/
@apply transition duration-250 motion-reduce:transition-none;
/* Checkmark SVG indicator */
[data-slot="list-box-item-indicator--checkmark"] {
@apply size-2.5;
/**
* Transitions
*/
@apply transition-all duration-300 motion-reduce:transition-none;
}
.hv-list-box-item[aria-selected="true"]
[data-slot="list-box-item-indicator--checkmark"],
.hv-list-box-item[data-selected="true"]
[data-slot="list-box-item-indicator--checkmark"] {
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition: stroke-dashoffset 250ms linear;
@apply motion-reduce:transition-none;
}
}
/* Default variant */
.hv-list-box-item--default {
}
/* Danger variant */
.hv-list-box-item--danger {
.hv-list-box-item__indicator {
@apply text-danger;
}
[data-slot="label"] {
@apply text-danger;
}
}