5e688680e9
Port the fixed-baseline Autocomplete onto the B02a collection protocol. The trigger is the single Tab entry; opening moves focus to the search box inside the popover, which owns filtering, aria-activedescendant and keyboard navigation while the list only tracks an active row. - Seven parts: root (field, value/open models, form value, owner wiring), trigger (anchor + activation), value (scoped slot with selectedItems and selectedText instead of copied item subtrees), indicator, clear button, popover (measured trigger width), filter (owns the search text and composes the inner SearchFieldInput into the combobox control). - Filter exposes input-value/update:inputValue/inputChange, matching ComboBox. - Confirming the active row in multiple mode now toggles it instead of replacing the accepted set (ComboBox shared the same bug). - ComboBox shows the accepted label on the first render via a display value that falls back to the selected record, so preselected fields are readable before the selection watcher runs (including SSR). - Popovers measure the anchor with a ResizeObserver because Reka does not publish the anchor size; the caller's root class is merged again so the trigger fills the field width. - 24 baseline previews, Chinese doc page, navigation, 17 behaviour tests, 5 demo/document contracts and an independent tarball consumption script for both pickers. Not included: the full bundler/NodeNext type matrix (B02d).
288 lines
7.9 KiB
CSS
288 lines
7.9 KiB
CSS
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||
/* Autocomplete styles */
|
||
.hv-autocomplete {
|
||
@apply flex flex-col gap-1;
|
||
}
|
||
|
||
.hv-autocomplete__trigger {
|
||
@apply relative isolate inline-flex min-h-9 rounded-field border bg-field px-3 py-2 text-sm text-field-foreground shadow-field outline-none select-none no-highlight;
|
||
|
||
/**
|
||
* Transitions
|
||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||
*/
|
||
transition:
|
||
background-color 150ms var(--ease-smooth),
|
||
border-color 150ms var(--ease-smooth),
|
||
box-shadow 150ms var(--ease-out);
|
||
@apply motion-reduce:transition-none;
|
||
|
||
/* Cursor */
|
||
cursor: var(--cursor-interactive);
|
||
|
||
border-width: var(--border-width-field);
|
||
border-color: var(--field-border);
|
||
|
||
/* Add inline-end padding when indicator is present */
|
||
&:has(.hv-autocomplete__indicator) {
|
||
@apply pe-7;
|
||
}
|
||
|
||
/* Hover state - exclude when clear button is hovered to prevent double hover effect */
|
||
@media (hover: hover) {
|
||
&:hover:not(:has(.hv-autocomplete__clear-button:hover)),
|
||
&[data-hovered="true"]:not(:has(.hv-autocomplete__clear-button:hover)) {
|
||
@apply bg-field-hover;
|
||
border-color: var(--field-border-hover);
|
||
}
|
||
}
|
||
|
||
/* Focus visible state */
|
||
&:focus-visible:not([data-focused]),
|
||
&[data-focus-visible="true"] {
|
||
@apply status-focused;
|
||
border-color: var(--field-border-focus);
|
||
background-color: var(--field-focus);
|
||
}
|
||
|
||
/* Focus state */
|
||
&:focus,
|
||
&[data-focus="true"] {
|
||
}
|
||
|
||
/* Invalid state */
|
||
.hv-autocomplete[data-invalid="true"] &,
|
||
.hv-autocomplete[aria-invalid="true"] & {
|
||
@apply status-invalid-field;
|
||
background-color: var(--field-focus);
|
||
}
|
||
|
||
/* Disabled state */
|
||
&:disabled,
|
||
&[data-disabled="true"],
|
||
&[aria-disabled="true"] {
|
||
@apply status-disabled;
|
||
}
|
||
}
|
||
|
||
/* Variant property definitions */
|
||
.hv-autocomplete--primary {
|
||
/* Default styles */
|
||
}
|
||
|
||
.hv-autocomplete--secondary .hv-autocomplete__trigger {
|
||
@apply shadow-none;
|
||
background-color: var(--hv-autocomplete-trigger-bg);
|
||
|
||
--hv-autocomplete-trigger-bg: var(--default);
|
||
--hv-autocomplete-trigger-bg-hover: var(--default-hover);
|
||
--hv-autocomplete-trigger-bg-focus: var(--default);
|
||
|
||
/* Exclude when clear button is hovered to prevent double hover effect */
|
||
@media (hover: hover) {
|
||
&:hover:not(:has(.hv-autocomplete__clear-button:hover)),
|
||
&[data-hovered="true"]:not(:has(.hv-autocomplete__clear-button:hover)) {
|
||
background-color: var(--hv-autocomplete-trigger-bg-hover);
|
||
}
|
||
}
|
||
|
||
&:focus-visible:not([data-focused]),
|
||
&[data-focus-visible="true"] {
|
||
background-color: var(--hv-autocomplete-trigger-bg-focus);
|
||
}
|
||
|
||
&:focus,
|
||
&[data-focus="true"] {
|
||
}
|
||
|
||
.hv-autocomplete[data-invalid="true"] &,
|
||
.hv-autocomplete[aria-invalid="true"] & {
|
||
background-color: var(--hv-autocomplete-trigger-bg-focus);
|
||
}
|
||
}
|
||
|
||
.hv-autocomplete__value {
|
||
@apply flex-1 text-start text-base wrap-break-word text-current sm:text-sm;
|
||
|
||
&[data-placeholder="true"] {
|
||
@apply text-field-placeholder;
|
||
}
|
||
|
||
/* Removes the list-box-item indicator element from the hv-autocomplete value*/
|
||
[data-slot="list-box-item-indicator"] {
|
||
@apply hidden;
|
||
}
|
||
}
|
||
|
||
.hv-autocomplete__indicator {
|
||
@apply absolute inset-y-0 end-2 my-auto flex shrink-0 items-center justify-center text-field-placeholder transition duration-150;
|
||
|
||
/* Cursor */
|
||
cursor: var(--cursor-interactive);
|
||
|
||
&[data-open="true"] {
|
||
@apply rotate-180;
|
||
}
|
||
|
||
&[data-slot="hv-autocomplete-default-indicator"] {
|
||
@apply size-4;
|
||
}
|
||
}
|
||
|
||
/* Similar to popover content styles */
|
||
.hv-autocomplete__popover {
|
||
@apply flex w-(--trigger-width) max-w-(--trigger-width) origin-(--trigger-anchor-point) scroll-py-1 flex-col overflow-hidden overscroll-contain bg-overlay p-0 pt-2 text-sm outline-none;
|
||
border-radius: min(32px, var(--radius-3xl));
|
||
box-shadow: var(--overlay-shadow);
|
||
|
||
&:focus,
|
||
&:focus-visible:not([data-focused]),
|
||
&[data-focus-visible="true"] {
|
||
@apply outline-none;
|
||
}
|
||
|
||
/* Entering animations */
|
||
&[data-entering="true"] {
|
||
@apply animate-in duration-250 ease-out-fluid fade-in-0 zoom-in-95;
|
||
|
||
/* Placement-specific translations */
|
||
&[data-placement="top"] {
|
||
@apply slide-in-from-bottom-1;
|
||
}
|
||
|
||
&[data-placement="bottom"] {
|
||
@apply slide-in-from-top-1;
|
||
}
|
||
|
||
&[data-placement="left"] {
|
||
@apply slide-in-from-right-1;
|
||
}
|
||
|
||
&[data-placement="right"] {
|
||
@apply slide-in-from-left-1;
|
||
}
|
||
}
|
||
|
||
/* Exiting animations */
|
||
&[data-exiting="true"] {
|
||
@apply animate-out duration-100 ease-out-quad zoom-out-95 fade-out;
|
||
/* Stays non-interactive while closing, even if the exit animation is interrupted. */
|
||
@apply pointer-events-none;
|
||
}
|
||
|
||
&[data-exiting="true"],
|
||
&[data-entering="true"] {
|
||
@apply transition-[opacity,transform] will-change-[opacity,transform];
|
||
}
|
||
|
||
/* Arrow styling */
|
||
& [data-slot="popover-overlay-arrow"] {
|
||
fill: var(--overlay);
|
||
}
|
||
|
||
/* Arrow rotation based on placement */
|
||
&[data-placement="bottom"] [data-slot="popover-overlay-arrow"] {
|
||
rotate: 180deg;
|
||
}
|
||
|
||
&[data-placement="left"] [data-slot="popover-overlay-arrow"] {
|
||
rotate: -90deg;
|
||
}
|
||
|
||
&[data-placement="right"] [data-slot="popover-overlay-arrow"] {
|
||
rotate: 90deg;
|
||
}
|
||
|
||
/* Listbox styles.
|
||
* `min-h-0` + the popover's flex column let the list shrink below 320px when the
|
||
* popover itself is constrained (e.g. inside a Modal, or a short viewport). Without
|
||
* it the list keeps its full 320px and its overflow is clipped by the popover, making
|
||
* the last options unreachable. */
|
||
[data-slot="list-box"] {
|
||
@apply max-h-[320px] min-h-0 scrollbar overflow-y-auto p-1.5 outline-none;
|
||
}
|
||
|
||
[data-slot="list-box-item"] {
|
||
@apply px-2.5;
|
||
}
|
||
|
||
/* Virtualized rows: react-aria's Virtualizer wraps each row in an absolutely-positioned
|
||
* [role="presentation"] element whose width equals the scroll container's clientWidth
|
||
* (which includes the list-box horizontal padding) while sitting inside the padded content
|
||
* box. Without this, rows overflow the right padding and the hover background reaches the
|
||
* popover edge. Subtract the horizontal padding (2 × p-1.5 = 12px) to keep rows aligned. */
|
||
[role="presentation"] > [data-slot="list-box-item"] {
|
||
width: calc(100% - var(--spacing) * 3);
|
||
}
|
||
|
||
/* As the popover closes fast in single-select mode, the default item indicator transition is not even visible - so we disable it only for single-select */
|
||
[data-slot="list-box"]:not([aria-multiselectable="true"])
|
||
[data-slot="list-box-item-indicator"],
|
||
[data-slot="list-box"]:not([aria-multiselectable="true"])
|
||
[data-slot="list-box-item-indicator"]
|
||
[data-slot="list-box-item-indicator--checkmark"] {
|
||
@apply transition-none;
|
||
}
|
||
|
||
/* Search Field styles */
|
||
[data-slot="search-field"] {
|
||
@apply shrink-0 px-3 py-1 outline-none;
|
||
}
|
||
|
||
/* Empty State */
|
||
[data-slot="empty-state"] {
|
||
@apply text-center text-sm text-overlay-foreground/60;
|
||
}
|
||
}
|
||
|
||
/* Full width modifier */
|
||
.hv-autocomplete--full-width {
|
||
@apply w-full;
|
||
}
|
||
|
||
.hv-autocomplete__trigger--full-width {
|
||
@apply w-full;
|
||
}
|
||
|
||
/* Clear Button styles */
|
||
.hv-autocomplete__clear-button {
|
||
@apply relative isolate inline-flex h-6 w-6 shrink-0 origin-center items-center justify-center rounded-xl p-1 text-muted select-none no-highlight;
|
||
@apply me-0 size-5 shrink-0 self-center bg-transparent;
|
||
|
||
/* Cursor */
|
||
cursor: var(--cursor-interactive);
|
||
|
||
@apply transform-gpu;
|
||
|
||
/* Transition only when visible - disappears immediately when cleared */
|
||
&:not([data-empty="true"]) {
|
||
transition: opacity 150ms var(--ease-smooth);
|
||
@apply motion-reduce:transition-none;
|
||
}
|
||
|
||
&[data-empty="true"] {
|
||
@apply pointer-events-none opacity-0;
|
||
}
|
||
|
||
[data-slot="hv-autocomplete-clear-button-icon"] {
|
||
@apply size-3.5;
|
||
}
|
||
|
||
&:active,
|
||
&[data-pressed="true"] {
|
||
}
|
||
|
||
@media (hover: hover) {
|
||
&:hover,
|
||
&[data-hovered="true"] {
|
||
@apply bg-default-hover;
|
||
}
|
||
}
|
||
|
||
&:active,
|
||
&[data-pressed="true"] {
|
||
transform: scale(0.93);
|
||
}
|
||
}
|