@acusti/dropdown 1.0.0-alpha.2 → 1.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -266,6 +266,14 @@ type Props = {
266
266
  onMouseDown?: (event: React.MouseEvent<HTMLElement>) => unknown;
267
267
  onMouseUp?: (event: React.MouseEvent<HTMLElement>) => unknown;
268
268
  onOpen?: () => unknown;
269
+ /**
270
+ * Opens the dropdown when the pointer hovers the trigger, and closes it a
271
+ * short moment after the pointer leaves the trigger and body entirely (the
272
+ * close is delayed so crossing the gap between them, or pausing over
273
+ * either, doesn’t flicker-close it). Click and keyboard opening keep
274
+ * working as usual alongside it.
275
+ */
276
+ openOnHover?: boolean;
269
277
  /**
270
278
  * Called when an item is selected. The payload includes:
271
279
  * - element: The DOM element that was clicked
@@ -427,6 +435,29 @@ function MultiSelectDropdown() {
427
435
  }
428
436
  ```
429
437
 
438
+ ### Open on Hover
439
+
440
+ ```tsx
441
+ function HoverMenu() {
442
+ return (
443
+ <Dropdown openOnHover>
444
+ <button type="button">Account</button>
445
+ <ul>
446
+ <li>Profile</li>
447
+ <li>Settings</li>
448
+ <li>Sign out</li>
449
+ </ul>
450
+ </Dropdown>
451
+ );
452
+ }
453
+ ```
454
+
455
+ Click and keyboard opening (Enter/Space while focused) still work —
456
+ hovering is an additional way in, not a replacement. This makes the most
457
+ sense for a dropdown whose body is inspectable at a glance (a short menu, a
458
+ preview card); for anything the user needs to click into, keep the default
459
+ click-to-open behavior so a stray hover doesn’t pop it open.
460
+
430
461
  ### Dropdown with Interactive Content
431
462
 
432
463
  For dropdowns whose body is a form (inputs, date pickers, buttons that
@@ -483,9 +514,9 @@ Example:
483
514
 
484
515
  ```css
485
516
  .settings-dropdown {
486
- --uktdd-body-position-area: bottom span-left;
517
+ --uktdd-body-position-area: block-end span-inline-start;
487
518
  --uktdd-body-position-try-fallbacks:
488
- --uktdd-top-right, --uktdd-bottom-left, --uktdd-top-left;
519
+ --uktdd-top-end, --uktdd-bottom-start, --uktdd-top-start;
489
520
  --uktdd-body-gap: 8px;
490
521
  }
491
522
 
@@ -497,6 +528,54 @@ Example:
497
528
  This approach keeps the public React API small while still allowing precise
498
529
  placement and sizing control when a product surface needs it.
499
530
 
531
+ ### Changing the Default Direction
532
+
533
+ `--uktdd-body-position-area` and `--uktdd-body-position-try-fallbacks`
534
+ always change together. `--uktdd-body-position-area` is the primary
535
+ placement, used whenever it fits in the viewport — that’s what actually
536
+ determines the direction a dropdown opens by default. The fallbacks list is
537
+ only consulted when the primary placement doesn’t fit, so overriding it
538
+ alone changes nothing in the common case where the primary already fits.
539
+ Overriding the primary alone works, but leaves behind a fallback cascade
540
+ tuned for the old primary — in a cramped viewport, the dropdown can fall
541
+ back toward the direction you just moved away from.
542
+
543
+ The four `@position-try` blocks the component ships (`--uktdd-top-start`,
544
+ `--uktdd-top-end`, `--uktdd-bottom-start`, `--uktdd-bottom-end`) are named
545
+ for the aligned edge, not the direction the body extends toward: `start`
546
+ opens with the body’s inline-start edge flush with the trigger’s
547
+ inline-start edge (extending toward inline-end), and `end` is the mirror
548
+ image. This also means they’re RTL-safe — `start`/`end` follow the
549
+ document’s writing direction the way `left`/`right` wouldn’t. The values
550
+ pair `block-start`/`block-end` with `span-inline-start`/`span-inline-end`
551
+ rather than `top`/`bottom` — `position-area` doesn’t allow mixing a
552
+ physical keyword on one axis with a logical one on the other — though
553
+ `block-start`/`block-end` read as `top`/`bottom` in the near-universal
554
+ horizontal-tb writing mode.
555
+
556
+ Pick the row matching the direction you want, and set both variables to its
557
+ pair:
558
+
559
+ | Direction | `--uktdd-body-position-area` | `--uktdd-body-position-try-fallbacks` |
560
+ | ----------------------------------- | ------------------------------- | ------------------------------------------------------------- |
561
+ | Bottom, start-aligned (the default) | `block-end span-inline-end` | `--uktdd-top-start, --uktdd-bottom-end, --uktdd-top-end` |
562
+ | Bottom, end-aligned | `block-end span-inline-start` | `--uktdd-top-end, --uktdd-bottom-start, --uktdd-top-start` |
563
+ | Top, start-aligned | `block-start span-inline-end` | `--uktdd-bottom-start, --uktdd-top-end, --uktdd-bottom-end` |
564
+ | Top, end-aligned | `block-start span-inline-start` | `--uktdd-bottom-end, --uktdd-top-start, --uktdd-bottom-start` |
565
+
566
+ For example, to make a dropdown open upward and end-aligned (useful for a
567
+ trigger pinned to the bottom of the viewport, near the inline-end edge):
568
+
569
+ ```css
570
+ .bottom-toolbar-dropdown {
571
+ --uktdd-body-position-area: block-start span-inline-start;
572
+ --uktdd-body-position-try-fallbacks:
573
+ --uktdd-bottom-end, --uktdd-top-start, --uktdd-bottom-start;
574
+ }
575
+ ```
576
+
577
+ See the `DirectionRecipes` story for a live demo of all four.
578
+
500
579
  Use `--uktdd-body-gap` for the space between the trigger and the body. It
501
580
  is applied as a symmetric `margin-block`, so the gap lands on whichever
502
581
  side the body attaches to and auto-reverses when `position-try` flips the
@@ -517,9 +596,9 @@ the menu size itself from its contents.
517
596
 
518
597
  ```css
519
598
  .avatar-menu {
520
- --uktdd-body-position-area: bottom span-left;
599
+ --uktdd-body-position-area: block-end span-inline-start;
521
600
  --uktdd-body-position-try-fallbacks:
522
- --uktdd-top-right, --uktdd-top-left, --uktdd-bottom-right;
601
+ --uktdd-top-end, --uktdd-top-start, --uktdd-bottom-end;
523
602
  }
524
603
  ```
525
604
 
@@ -645,9 +724,11 @@ Most props keep their meaning, scoped to the submenu:
645
724
  - `className`/`style`: applied to the parent item element
646
725
 
647
726
  Props that only make sense at the top level (`allowCreate`, `allowEmpty`,
648
- `isOpenOnMount`, `isSearchable`, `keepOpenOnSubmit`, `name`, `placeholder`,
649
- `tabIndex`, `value`) are ignored on a nested dropdown and warn
650
- (unconditionally, matching the children-count misuse error).
727
+ `isOpenOnMount`, `isSearchable`, `keepOpenOnSubmit`, `name`, `openOnHover`,
728
+ `placeholder`, `tabIndex`, `value`) are ignored on a nested dropdown and
729
+ warn (unconditionally, matching the children-count misuse error). A submenu
730
+ already discloses on hover intent — see [Submenus](#submenus) — so
731
+ `openOnHover` has nothing to add there.
651
732
 
652
733
  ### Submenu placement and styling
653
734
 
@@ -57,6 +57,14 @@ export type Props = {
57
57
  onMouseUp?: (event: ReactMouseEvent<HTMLElement>) => unknown;
58
58
  onOpen?: () => unknown;
59
59
  onSubmitItem?: (payload: Item) => void;
60
+ /**
61
+ * Opens the dropdown when the pointer hovers the trigger, and closes it a
62
+ * short moment after the pointer leaves the trigger and body entirely (the
63
+ * close is delayed so crossing the gap between them, or pausing over
64
+ * either, doesn’t flicker-close it). Click and keyboard opening keep
65
+ * working as usual alongside it.
66
+ */
67
+ openOnHover?: boolean;
60
68
  /**
61
69
  * Only usable in conjunction with {isSearchable: true}.
62
70
  * Used as search input’s placeholder.