swarm-ui: an open dropdown closes only on a scroll that moves it
This commit is contained in:
parent
a2e8a2bda0
commit
32a4821cb4
1 changed files with 6 additions and 3 deletions
|
|
@ -15,8 +15,8 @@
|
|||
// layer: it is not clipped by a scrolling ancestor, and inside a modal
|
||||
// `<dialog>` it shows above the dialog (it is a descendant of the control, so
|
||||
// the dialog's inertness leaves it alone). `position: fixed` coordinates come
|
||||
// from the control's box (`placePopup`). A scroll or resize elsewhere, or a
|
||||
// click outside, closes it, as a native select's list closes.
|
||||
// from the control's box (`placePopup`). A scroll that moves the control, a
|
||||
// resize, or a click outside closes it, as a native select's list closes.
|
||||
//
|
||||
// Not a native control, so there is no form validation: `required` is only
|
||||
// `aria-required`, and a caller that needs a choice checks it itself.
|
||||
|
|
@ -129,8 +129,11 @@ export function Listbox({
|
|||
if (!triggerRef.current?.contains(t) && !listRef.current?.contains(t))
|
||||
closeList();
|
||||
}
|
||||
// Only a scroll that moves the control closes it: the page, or a box the
|
||||
// control sits in. A live terminal scrolling itself elsewhere on the page
|
||||
// must not shut it under the pointer.
|
||||
function onScroll(e: Event) {
|
||||
if (!listRef.current?.contains(e.target as Node)) closeList();
|
||||
if ((e.target as Node).contains(triggerRef.current)) closeList();
|
||||
}
|
||||
document.addEventListener("pointerdown", onPointerDown);
|
||||
window.addEventListener("scroll", onScroll, true);
|
||||
|
|
|
|||
Loading…
Reference in a new issue