feat(combo-box): migrate ComboBox with input-owned focus and filtering

Port the fixed-baseline ComboBox onto the B02a collection protocol: the input
keeps real DOM focus, the list only tracks an active row, and filtering reuses
the owner filter instead of a second collection kernel.

- Five parts: root (field text control, value/input/open models, form value,
  owner wiring), InputGroup (composes the caller's Input into the combobox
  control and anchors the popover), Trigger, Value, Popover.
- Closed-state metadata is planned from the slot tree, so filtering, the initial
  value label and form-value="text" work before the list has mounted.
- Selection text syncs on selection changes only, so allows-custom-value typing
  is not overwritten; read-only and disabled are injected onto the composed
  input because it reads the text-field protocol, not the field context.
- 24 baseline previews, the Chinese doc page, navigation, 19 behaviour tests and
  6 demo/document contracts. Async demo uses a local async source with abort,
  loading and incremental append (documented adaptations).

Not included: independent tarball consumption (B02d).
This commit is contained in:
maoyingjie
2026-10-25 16:59:16 +08:00
parent ff486fb665
commit 46e4df7e85
46 changed files with 4322 additions and 2 deletions
+188
View File
@@ -0,0 +1,188 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
/* ComboBox styles */
.hv-combo-box {
@apply flex flex-col gap-1;
&[data-invalid="true"],
&[aria-invalid="true"] {
[data-slot="description"] {
@apply hidden;
}
}
[data-slot="label"] {
@apply w-fit;
}
[data-slot="input"] {
@apply min-w-0 flex-1;
/* Add inline-end padding when trigger is present */
&:has(+ .hv-combo-box__trigger) {
@apply pe-7;
}
/* Focus state (input.css only has focus-visible, but hv-combo-box also needs focus) */
&:focus,
&[data-focus] {
@apply status-focused-field;
border-color: var(--field-border-focus);
background-color: var(--field-focus);
}
/* Disabled state */
&:disabled,
&[data-disabled],
&[aria-disabled="true"] {
@apply status-disabled;
}
}
}
.hv-combo-box__input-group {
@apply relative isolate inline-flex items-center;
}
.hv-combo-box__value {
@apply text-sm wrap-break-word text-field-foreground empty:hidden;
&[data-placeholder="true"] {
@apply text-field-placeholder;
}
/* Removes the list-box-item indicator element from the hv-combo-box value */
[data-slot="list-box-item-indicator"] {
@apply hidden;
}
}
.hv-combo-box__trigger {
@apply absolute end-0 top-1/2 flex h-full shrink-0 -translate-y-1/2 cursor-pointer items-center justify-center pe-2 text-field-placeholder transition duration-150 no-highlight;
/* Remove default button styles */
@apply border-none bg-transparent outline-none;
/* Hover state */
@media (hover: hover) {
&:hover,
&[data-hovered="true"] {
@apply text-field-foreground;
}
}
/* Focus visible state */
&:focus-visible:not([data-focused]),
&[data-focus-visible="true"] {
@apply rounded ring-2 ring-focus ring-offset-2 ring-offset-background outline-none;
}
/* Pressed state */
&[data-pressed="true"] {
@apply opacity-70;
}
/* Disabled state */
&:disabled,
&[data-disabled],
&[aria-disabled="true"] {
@apply cursor-not-allowed opacity-50;
}
[data-slot="hv-combo-box-trigger-default-icon"] {
@apply size-4 transition-transform duration-150 motion-reduce:transition-none;
}
/* Rotate icon when trigger is open */
&[data-open="true"] [data-slot="hv-combo-box-trigger-default-icon"] {
@apply rotate-180;
}
}
/* Similar to popover content styles */
.hv-combo-box__popover {
@apply min-w-(--trigger-width) origin-(--trigger-anchor-point) scroll-py-1 scrollbar overflow-y-auto overscroll-contain bg-overlay p-0 text-sm;
border-radius: min(32px, var(--radius-3xl));
box-shadow: var(--overlay-shadow);
/* Focus state */
&:focus-visible:not([data-focused]),
&[data-focus-visible="true"] {
@apply outline-none;
}
/* Entering animations */
&[data-entering="true"] {
@apply animate-in duration-150 ease-smooth 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-smooth 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 */
[data-slot="list-box"] {
@apply p-1.5 outline-none;
}
[data-slot="list-box-item"] {
@apply px-2.5;
/* As the hv-combo-box is single-select, we don't need to animate the checkmark */
[data-slot="list-box-item-indicator--checkmark"] {
@apply transition-none;
}
}
}
/* Full width modifier */
.hv-combo-box--full-width {
@apply w-full;
}
.hv-combo-box__input-group--full-width {
@apply w-full;
}