@barqjs/aria 0.2.0-next.0 → 0.2.0-next.1
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 +24 -13
- package/package.json +127 -37
- package/src/autocomplete.tsx +581 -0
- package/src/breadcrumbs.tsx +21 -20
- package/src/button.tsx +151 -25
- package/src/calendar.tsx +1019 -92
- package/src/checkbox.tsx +214 -52
- package/src/collections.ts +88 -5
- package/src/color.ts +1580 -23
- package/src/colorpicker.tsx +698 -153
- package/src/colorswatchpicker.tsx +240 -0
- package/src/combobox.tsx +635 -113
- package/src/command.tsx +78 -59
- package/src/date.ts +31 -9
- package/src/datefield.tsx +1451 -336
- package/src/datepicker.tsx +465 -114
- package/src/dialog.tsx +302 -115
- package/src/disclosure.tsx +81 -29
- package/src/dnd/clipboard.ts +125 -0
- package/src/dnd/collection.ts +1265 -0
- package/src/dnd/data.ts +409 -0
- package/src/dnd/drag-drop.ts +801 -0
- package/src/dnd/index.ts +133 -0
- package/src/dnd/manager.ts +639 -0
- package/src/dnd/strings.ts +1279 -0
- package/src/dnd/targets.ts +726 -0
- package/src/dnd/types.ts +212 -0
- package/src/dom.ts +3 -6
- package/src/drag-and-drop.tsx +669 -0
- package/src/dropzone.tsx +208 -0
- package/src/file-trigger.tsx +103 -0
- package/src/form.tsx +18 -18
- package/src/gridlist.tsx +912 -121
- package/src/group.tsx +146 -0
- package/src/index.ts +402 -0
- package/src/interactions/focus-events.ts +13 -5
- package/src/interactions/keyboard.ts +195 -2
- package/src/interactions/modality.ts +18 -6
- package/src/interactions/open-link.ts +46 -13
- package/src/interactions/press.ts +35 -18
- package/src/label.ts +18 -6
- package/src/link.tsx +146 -50
- package/src/listbox.tsx +615 -89
- package/src/live.ts +4 -0
- package/src/menu.tsx +182 -89
- package/src/menubar.tsx +21 -17
- package/src/navigation-tree.tsx +357 -0
- package/src/numberfield.tsx +164 -60
- package/src/overlay-arrow.tsx +157 -0
- package/src/overlays.ts +364 -62
- package/src/platform.ts +2 -1
- package/src/preview-trigger.tsx +582 -0
- package/src/progress-bar-context.ts +15 -0
- package/src/questionnaire.tsx +109 -104
- package/src/radio.tsx +101 -27
- package/src/select.tsx +225 -145
- package/src/selection-indicator.tsx +74 -0
- package/src/selection.ts +73 -16
- package/src/shared-element-transition.tsx +316 -0
- package/src/sheet.tsx +1461 -0
- package/src/slider.tsx +139 -44
- package/src/switch.tsx +47 -21
- package/src/table.tsx +0 -0
- package/src/tabs.tsx +198 -89
- package/src/tag.tsx +217 -32
- package/src/textarea.tsx +186 -0
- package/src/textfield.tsx +103 -37
- package/src/toast-components.tsx +589 -0
- package/src/toggle-button-group.tsx +175 -0
- package/src/toggle-input.tsx +38 -0
- package/src/toggle.ts +68 -5
- package/src/tokenfield.tsx +1673 -0
- package/src/toolbar.tsx +15 -10
- package/src/tooltip.tsx +46 -29
- package/src/tree.tsx +2075 -0
- package/src/utils.ts +30 -1
- package/src/validation.ts +79 -22
- package/src/virtualizer.tsx +186 -23
package/src/overlays.ts
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
ownerDocument,
|
|
37
37
|
ownerWindow,
|
|
38
38
|
propagationTargets,
|
|
39
|
+
scrollIntoViewport,
|
|
39
40
|
scrollParents,
|
|
40
41
|
setStyle,
|
|
41
42
|
targetElement,
|
|
@@ -45,7 +46,9 @@ import { resizeObserver } from "@barqjs/primitives/observers";
|
|
|
45
46
|
|
|
46
47
|
import { focusWithin } from "./interactions/focus-events.ts";
|
|
47
48
|
import { interactOutside } from "./interactions/interact-outside.ts";
|
|
49
|
+
import { isTextEntry } from "./interactions/modality.ts";
|
|
48
50
|
import type { ElementRef } from "./interactions/press.ts";
|
|
51
|
+
import { StringDictionary, stringFormatter } from "./i18n.ts";
|
|
49
52
|
import { isIOS, isWebKit } from "./platform.ts";
|
|
50
53
|
import {
|
|
51
54
|
access,
|
|
@@ -325,6 +328,11 @@ export function overlay(options: OverlayOptions, ref: ElementRef): OverlayResult
|
|
|
325
328
|
// for focus genuinely moving elsewhere.
|
|
326
329
|
const related = event.relatedTarget as Element | null;
|
|
327
330
|
if (related === null) return;
|
|
331
|
+
// Focus going into a submenu, or into an overlay this one opened, has
|
|
332
|
+
// not left: both are this overlay's own, wherever they are mounted.
|
|
333
|
+
if (contains(access(inside), related)) return;
|
|
334
|
+
const above = openOverlays.slice(openOverlays.indexOf(ref) + 1);
|
|
335
|
+
if (above.some((child) => contains(access(child), related))) return;
|
|
328
336
|
if (shouldClose(related)) options.onClose?.();
|
|
329
337
|
},
|
|
330
338
|
});
|
|
@@ -686,21 +694,126 @@ function preventScrollWebKitIOS(): () => void {
|
|
|
686
694
|
// Injected as a stylesheet because iOS 26 requires it to be in effect before
|
|
687
695
|
// the touchstart, which a property set in the handler is not.
|
|
688
696
|
const style = document.createElement("style");
|
|
697
|
+
const nonce = cspNonce(document);
|
|
698
|
+
if (nonce !== undefined) style.nonce = nonce;
|
|
689
699
|
style.textContent = "@layer{*{overscroll-behavior:contain}}";
|
|
690
700
|
document.head.prepend(style);
|
|
691
701
|
|
|
702
|
+
const restoreFocus = overrideFocus();
|
|
692
703
|
const removeEvents = chain(
|
|
693
704
|
addEvent(document, "touchstart", onTouchStart, { passive: false, capture: true }),
|
|
694
705
|
addEvent(document, "touchmove", onTouchMove, { passive: false, capture: true }),
|
|
706
|
+
addEvent(document, "blur", onBlurForKeyboard, true),
|
|
695
707
|
);
|
|
696
708
|
|
|
697
709
|
return () => {
|
|
698
710
|
restoreOverflow();
|
|
699
711
|
removeEvents();
|
|
700
712
|
style.remove();
|
|
713
|
+
restoreFocus();
|
|
701
714
|
};
|
|
702
715
|
}
|
|
703
716
|
|
|
717
|
+
/**
|
|
718
|
+
* The nonce a Content Security Policy wants on an injected `<style>`, as the
|
|
719
|
+
* page publishes it: a `csp-nonce` meta tag, or the bundler's global.
|
|
720
|
+
*/
|
|
721
|
+
function cspNonce(doc: Document): string | undefined {
|
|
722
|
+
const view = doc.defaultView;
|
|
723
|
+
const meta = doc.querySelector('meta[name="csp-nonce"], meta[property="csp-nonce"]');
|
|
724
|
+
if (view !== null && meta instanceof view.HTMLMetaElement) {
|
|
725
|
+
const declared = meta.nonce || meta.content;
|
|
726
|
+
if (declared) return declared;
|
|
727
|
+
}
|
|
728
|
+
const bundled =
|
|
729
|
+
(view as { __webpack_nonce__?: string } | null)?.__webpack_nonce__ ??
|
|
730
|
+
(globalThis as { __webpack_nonce__?: string }).__webpack_nonce__;
|
|
731
|
+
return bundled === undefined || bundled === "" ? undefined : bundled;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Run once the on-screen keyboard has finished appearing, if focus is about to
|
|
736
|
+
* bring it up, and straight away otherwise.
|
|
737
|
+
*
|
|
738
|
+
* Two frames for focus to land, then the visual viewport's resize, which is
|
|
739
|
+
* the keyboard arriving. A keyboard that never arrives (a hardware one is
|
|
740
|
+
* attached) is given up on after the time iOS takes to animate one in.
|
|
741
|
+
*/
|
|
742
|
+
function afterKeyboard(run: () => void): void {
|
|
743
|
+
const view = window;
|
|
744
|
+
view.requestAnimationFrame(() => {
|
|
745
|
+
view.requestAnimationFrame(() => {
|
|
746
|
+
const visual = view.visualViewport;
|
|
747
|
+
if (visual === null || visual === undefined || !isTextEntry(document.activeElement)) {
|
|
748
|
+
run();
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
let done = false;
|
|
752
|
+
const finish = (): void => {
|
|
753
|
+
if (done) return;
|
|
754
|
+
done = true;
|
|
755
|
+
visual.removeEventListener("resize", finish);
|
|
756
|
+
clearTimeout(timer);
|
|
757
|
+
run();
|
|
758
|
+
};
|
|
759
|
+
const timer = setTimeout(finish, KEYBOARD_TIMEOUT);
|
|
760
|
+
visual.addEventListener("resize", finish);
|
|
761
|
+
});
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
/** How long iOS takes to bring the on-screen keyboard in. */
|
|
766
|
+
const KEYBOARD_TIMEOUT = 600;
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Programmatic focus that does not scroll the page.
|
|
770
|
+
*
|
|
771
|
+
* WebKit on iOS scrolls the whole page to centre a focused field, which moves
|
|
772
|
+
* even a fixed modal off the screen. Focus is taken without scrolling, and the
|
|
773
|
+
* field is brought into view by its own scroll parents once the keyboard has
|
|
774
|
+
* taken its share of the screen.
|
|
775
|
+
*/
|
|
776
|
+
function overrideFocus(): () => void {
|
|
777
|
+
const prototype = HTMLElement.prototype;
|
|
778
|
+
const own = Object.getOwnPropertyDescriptor(prototype, "focus");
|
|
779
|
+
const focus = Reflect.get(prototype, "focus");
|
|
780
|
+
Reflect.defineProperty(prototype, "focus", {
|
|
781
|
+
configurable: true,
|
|
782
|
+
writable: true,
|
|
783
|
+
value(this: HTMLElement, options?: FocusOptions) {
|
|
784
|
+
focus.call(this, { ...options, preventScroll: true });
|
|
785
|
+
if (options?.preventScroll === true) return;
|
|
786
|
+
afterKeyboard(() => {
|
|
787
|
+
if (ownerDocument(this).activeElement === this) scrollIntoViewport(this);
|
|
788
|
+
});
|
|
789
|
+
},
|
|
790
|
+
});
|
|
791
|
+
return () => {
|
|
792
|
+
if (own === undefined) Reflect.deleteProperty(prototype, "focus");
|
|
793
|
+
else Reflect.defineProperty(prototype, "focus", own);
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Route focus moves that WebKit makes itself through {@link overrideFocus}.
|
|
799
|
+
*
|
|
800
|
+
* Tapping a field focuses it natively, which scrolls the page; focusing it
|
|
801
|
+
* again from here takes the path that does not. The keyboard's Done button
|
|
802
|
+
* sends focus to the body, and the next tap on the same field then fires no
|
|
803
|
+
* blur at all, so focus goes to the nearest focusable ancestor instead.
|
|
804
|
+
*/
|
|
805
|
+
function onBlurForKeyboard(event: Event): void {
|
|
806
|
+
const blur = event as FocusEvent;
|
|
807
|
+
const target = targetElement(blur);
|
|
808
|
+
const related = blur.relatedTarget as HTMLElement | null;
|
|
809
|
+
if (related !== null && isTextEntry(related)) {
|
|
810
|
+
related.focus();
|
|
811
|
+
} else if (related === null) {
|
|
812
|
+
const holder = target?.parentElement?.closest<HTMLElement>("[tabindex]") ?? null;
|
|
813
|
+
holder?.focus({ preventScroll: true });
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
704
817
|
// ---------------------------------------------------------------------------
|
|
705
818
|
// Positioning
|
|
706
819
|
// ---------------------------------------------------------------------------
|
|
@@ -783,6 +896,11 @@ export interface PositionOptions {
|
|
|
783
896
|
containerPadding?: MaybeAccessor<number | undefined>;
|
|
784
897
|
/** The arrow element, so it can be centred on the target. */
|
|
785
898
|
arrowRef?: ElementRef;
|
|
899
|
+
/**
|
|
900
|
+
* The least distance between the arrow and the overlay's ends, so it stays
|
|
901
|
+
* clear of a rounded corner. @default 0
|
|
902
|
+
*/
|
|
903
|
+
arrowBoundaryOffset?: MaybeAccessor<number | undefined>;
|
|
786
904
|
isOpen?: MaybeAccessor<boolean | undefined>;
|
|
787
905
|
onClose?: () => void;
|
|
788
906
|
/** Text direction, for `start` and `end` placements. @default "ltr" */
|
|
@@ -849,7 +967,7 @@ function layoutSize(element: Element): { width: number; height: number } {
|
|
|
849
967
|
|
|
850
968
|
function place(
|
|
851
969
|
target: Box,
|
|
852
|
-
panel:
|
|
970
|
+
panel: { width: number; height: number },
|
|
853
971
|
axis: Axis,
|
|
854
972
|
align: string,
|
|
855
973
|
offset: number,
|
|
@@ -879,26 +997,97 @@ function place(
|
|
|
879
997
|
return { top, left };
|
|
880
998
|
}
|
|
881
999
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
1000
|
+
/** The room between the target and the boundary on one side, past the offset and the padding. */
|
|
1001
|
+
function spaceOn(axis: Axis, target: Box, boundary: Box, offset: number, padding: number): number {
|
|
1002
|
+
const room =
|
|
1003
|
+
axis === "top"
|
|
1004
|
+
? target.top - boundary.top
|
|
1005
|
+
: axis === "bottom"
|
|
1006
|
+
? boundary.top + boundary.height - (target.top + target.height)
|
|
1007
|
+
: axis === "left"
|
|
1008
|
+
? target.left - boundary.left
|
|
1009
|
+
: boundary.left + boundary.width - (target.left + target.width);
|
|
1010
|
+
return Math.max(0, room - offset - padding);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* How far to move an overlay along one axis so it stays inside the boundary.
|
|
1015
|
+
*
|
|
1016
|
+
* When it is bigger than the boundary its START edge wins, so the beginning of
|
|
1017
|
+
* a list too long for the screen is what stays in view.
|
|
1018
|
+
*/
|
|
1019
|
+
function shiftInto(start: number, size: number, low: number, high: number): number {
|
|
1020
|
+
if (start < low) return low - start;
|
|
1021
|
+
if (start + size > high) return Math.max(high - (start + size), low - start);
|
|
1022
|
+
return 0;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* What an overlay inside the page is laid out in: the area the user can see.
|
|
1027
|
+
*
|
|
1028
|
+
* The visual viewport where there is one. A pinch-zoomed page and an iOS page
|
|
1029
|
+
* with the on-screen keyboard up both show less than `innerHeight`, and an
|
|
1030
|
+
* overlay sized to the layout viewport is cut off behind the keyboard.
|
|
1031
|
+
*/
|
|
1032
|
+
function visibleViewport(view: Window): Box {
|
|
1033
|
+
const visual = view.visualViewport;
|
|
1034
|
+
if (visual !== null && visual !== undefined) {
|
|
1035
|
+
return {
|
|
1036
|
+
top: visual.offsetTop,
|
|
1037
|
+
left: visual.offsetLeft,
|
|
1038
|
+
width: visual.width,
|
|
1039
|
+
height: visual.height,
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
return { top: 0, left: 0, width: view.innerWidth, height: view.innerHeight };
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/** A computed value that is set, which happy-dom reports as "" rather than "none". */
|
|
1046
|
+
function isSet(value: string | undefined): boolean {
|
|
1047
|
+
return value !== undefined && value !== "" && value !== "none";
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
function establishesContainingBlock(style: CSSStyleDeclaration): boolean {
|
|
1051
|
+
const backdrop = (style as CSSStyleDeclaration & { webkitBackdropFilter?: string })
|
|
1052
|
+
.webkitBackdropFilter;
|
|
888
1053
|
return (
|
|
889
|
-
position
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
1054
|
+
(style.position !== "" && style.position !== "static") ||
|
|
1055
|
+
isSet(style.transform) ||
|
|
1056
|
+
/transform|perspective/.test(style.willChange) ||
|
|
1057
|
+
isSet(style.filter) ||
|
|
1058
|
+
style.contain === "paint" ||
|
|
1059
|
+
isSet(style.backdropFilter) ||
|
|
1060
|
+
isSet(backdrop)
|
|
893
1061
|
);
|
|
894
1062
|
}
|
|
895
1063
|
|
|
1064
|
+
/**
|
|
1065
|
+
* The element an absolutely positioned overlay is placed relative to, or
|
|
1066
|
+
* `null` for the initial containing block.
|
|
1067
|
+
*
|
|
1068
|
+
* An overlay portalled into a container of the page's own (a transformed
|
|
1069
|
+
* shell, a `position: relative` panel) is offset from THAT box, so page
|
|
1070
|
+
* coordinates put it wherever the container happens to sit away from the
|
|
1071
|
+
* page's origin.
|
|
1072
|
+
*/
|
|
1073
|
+
function containingBlock(element: Element): Element | null {
|
|
1074
|
+
const view = ownerWindow(element);
|
|
1075
|
+
const doc = ownerDocument(element);
|
|
1076
|
+
let node = element.parentElement;
|
|
1077
|
+
while (node !== null && node !== doc.documentElement) {
|
|
1078
|
+
if (establishesContainingBlock(view.getComputedStyle(node))) return node;
|
|
1079
|
+
node = node.parentElement;
|
|
1080
|
+
}
|
|
1081
|
+
return null;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
896
1084
|
/**
|
|
897
1085
|
* Place an overlay next to its trigger.
|
|
898
1086
|
*
|
|
899
1087
|
* The order is: try the requested side; flip to the opposite side if it does
|
|
900
|
-
* not fit
|
|
901
|
-
* inside the boundary; then cap the height to
|
|
1088
|
+
* not fit, flipping is allowed and the opposite side has more room; then shift
|
|
1089
|
+
* along the cross axis to stay inside the boundary; then cap the height to
|
|
1090
|
+
* what is left. Shifting after
|
|
902
1091
|
* flipping rather than instead of it is what keeps a popover pointing at its
|
|
903
1092
|
* trigger rather than sliding across the screen.
|
|
904
1093
|
*/
|
|
@@ -935,10 +1124,9 @@ export function overlayPosition(options: PositionOptions): PositionResult {
|
|
|
935
1124
|
|
|
936
1125
|
const boundaryElement = access(options.boundaryRef ?? undefined) as Element | null;
|
|
937
1126
|
const view = ownerWindow(element);
|
|
1127
|
+
const viewport = visibleViewport(view);
|
|
938
1128
|
const boundary: Box =
|
|
939
|
-
boundaryElement !== null && boundaryElement !== undefined
|
|
940
|
-
? boxOf(boundaryElement)
|
|
941
|
-
: { top: 0, left: 0, width: view.innerWidth, height: view.innerHeight };
|
|
1129
|
+
boundaryElement !== null && boundaryElement !== undefined ? boxOf(boundaryElement) : viewport;
|
|
942
1130
|
|
|
943
1131
|
// The overlay's LAYOUT size, not its painted one. Every overlay here enters
|
|
944
1132
|
// with `zoom-in-95`, so the first measurement caught it at 95% — a 288px
|
|
@@ -953,36 +1141,87 @@ export function overlayPosition(options: PositionOptions): PositionResult {
|
|
|
953
1141
|
|
|
954
1142
|
const [start, align] = resolveAxis(access(options.placement) ?? "bottom", direction);
|
|
955
1143
|
let axis = start;
|
|
956
|
-
let placed = place(targetBox, overlayBox, axis, align, offset, cross);
|
|
957
1144
|
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
1145
|
+
// Flip only on the MAIN axis, and to whichever side has more room. Whether
|
|
1146
|
+
// the overlay also overhangs sideways is the cross-axis shift's business,
|
|
1147
|
+
// and an overlay that fits neither side still belongs on the larger one,
|
|
1148
|
+
// where the height cap below costs it least.
|
|
1149
|
+
if (access(options.shouldFlip) !== false) {
|
|
1150
|
+
const size = axis === "top" || axis === "bottom" ? overlayBox.height : overlayBox.width;
|
|
1151
|
+
const room = spaceOn(axis, targetBox, boundary, offset, padding);
|
|
1152
|
+
if (size > room && spaceOn(OPPOSITE[axis], targetBox, boundary, offset, padding) > room) {
|
|
961
1153
|
axis = OPPOSITE[axis];
|
|
962
|
-
placed = flipped;
|
|
963
1154
|
}
|
|
964
1155
|
}
|
|
965
1156
|
|
|
1157
|
+
// What the height may grow to, inside both the boundary and what is
|
|
1158
|
+
// visible of the page.
|
|
1159
|
+
const visibleTop = Math.max(boundary.top, viewport.top);
|
|
1160
|
+
const visibleBottom = Math.min(boundary.top + boundary.height, viewport.top + viewport.height);
|
|
1161
|
+
|
|
1162
|
+
// An arrow is measured by its layout box too: it is usually a rotated
|
|
1163
|
+
// square, and `getBoundingClientRect` reports the box the rotation sweeps
|
|
1164
|
+
// out, wider than the arrow itself.
|
|
1165
|
+
const arrow = access(options.arrowRef ?? undefined) as Element | null;
|
|
1166
|
+
const arrowBox = arrow === null || arrow === undefined ? null : layoutSize(arrow);
|
|
1167
|
+
const vertical = axis === "top" || axis === "bottom";
|
|
1168
|
+
const arrowSize = arrowBox === null ? 0 : vertical ? arrowBox.width : arrowBox.height;
|
|
1169
|
+
const arrowEdge = access(options.arrowBoundaryOffset) ?? 0;
|
|
1170
|
+
|
|
966
1171
|
// Shift along the cross axis, never the main one: moving along the main
|
|
967
|
-
// axis would detach the overlay from its trigger.
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
1172
|
+
// axis would detach the overlay from its trigger. An overlay with an arrow
|
|
1173
|
+
// first keeps enough of itself over the trigger for the arrow to point at
|
|
1174
|
+
// it, however far a cross offset asked it to go.
|
|
1175
|
+
const shift = (at: { top: number; left: number }, height: number): void => {
|
|
1176
|
+
if (vertical) {
|
|
1177
|
+
if (arrowSize > 0) {
|
|
1178
|
+
at.left = clamp(
|
|
1179
|
+
at.left,
|
|
1180
|
+
targetBox.left - overlayBox.width + arrowSize + arrowEdge,
|
|
1181
|
+
targetBox.left + targetBox.width - arrowSize - arrowEdge,
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
at.left += shiftInto(
|
|
1185
|
+
at.left,
|
|
1186
|
+
overlayBox.width,
|
|
1187
|
+
boundary.left + padding,
|
|
1188
|
+
boundary.left + boundary.width - padding,
|
|
1189
|
+
);
|
|
1190
|
+
} else {
|
|
1191
|
+
if (arrowSize > 0) {
|
|
1192
|
+
at.top = clamp(
|
|
1193
|
+
at.top,
|
|
1194
|
+
targetBox.top - height + arrowSize + arrowEdge,
|
|
1195
|
+
targetBox.top + targetBox.height - arrowSize - arrowEdge,
|
|
1196
|
+
);
|
|
1197
|
+
}
|
|
1198
|
+
at.top += shiftInto(
|
|
1199
|
+
at.top,
|
|
1200
|
+
height,
|
|
1201
|
+
boundary.top + padding,
|
|
1202
|
+
boundary.top + boundary.height - padding,
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1207
|
+
let placed = place(targetBox, overlayBox, axis, align, offset, cross);
|
|
1208
|
+
shift(placed, overlayBox.height);
|
|
979
1209
|
|
|
980
1210
|
const maxHeight =
|
|
981
1211
|
axis === "top"
|
|
982
|
-
? targetBox.top - offset -
|
|
1212
|
+
? targetBox.top - offset - visibleTop - padding
|
|
983
1213
|
: axis === "bottom"
|
|
984
|
-
?
|
|
985
|
-
:
|
|
1214
|
+
? visibleBottom - padding - (targetBox.top + targetBox.height + offset)
|
|
1215
|
+
: align === "bottom" || align === "end"
|
|
1216
|
+
? placed.top + overlayBox.height - visibleTop - padding
|
|
1217
|
+
: visibleBottom - padding - placed.top;
|
|
1218
|
+
|
|
1219
|
+
// Placed again at the height it will have once capped. An overlay above
|
|
1220
|
+
// its trigger is positioned by its top edge, and it is the capped height
|
|
1221
|
+
// that puts its bottom edge against the trigger.
|
|
1222
|
+
const height = Math.min(overlayBox.height, Math.max(0, maxHeight));
|
|
1223
|
+
placed = place(targetBox, { width: overlayBox.width, height }, axis, align, offset, cross);
|
|
1224
|
+
shift(placed, height);
|
|
986
1225
|
|
|
987
1226
|
// The same question along the other axis. A menu placed to the RIGHT has
|
|
988
1227
|
// the space between its trigger and the boundary edge to grow into, and a
|
|
@@ -1011,14 +1250,27 @@ export function overlayPosition(options: PositionOptions): PositionResult {
|
|
|
1011
1250
|
axis === "bottom"
|
|
1012
1251
|
? 0
|
|
1013
1252
|
: axis === "top"
|
|
1014
|
-
?
|
|
1015
|
-
: clamp(targetBox.top + targetBox.height / 2 - placed.top, 0,
|
|
1253
|
+
? height
|
|
1254
|
+
: clamp(targetBox.top + targetBox.height / 2 - placed.top, 0, height);
|
|
1255
|
+
|
|
1256
|
+
// Everything so far is in client coordinates. Relative to the page, the
|
|
1257
|
+
// scroll offset is part of the answer; relative to a containing block of
|
|
1258
|
+
// the page's own, that block's box and its scroll are.
|
|
1259
|
+
const container = containingBlock(element);
|
|
1260
|
+
let originTop = -view.scrollY;
|
|
1261
|
+
let originLeft = -view.scrollX;
|
|
1262
|
+
if (container !== null) {
|
|
1263
|
+
const containerBox = container.getBoundingClientRect();
|
|
1264
|
+
const style = view.getComputedStyle(container);
|
|
1265
|
+
originTop =
|
|
1266
|
+
containerBox.top + (Number.parseFloat(style.borderTopWidth) || 0) - container.scrollTop;
|
|
1267
|
+
originLeft =
|
|
1268
|
+
containerBox.left + (Number.parseFloat(style.borderLeftWidth) || 0) - container.scrollLeft;
|
|
1269
|
+
}
|
|
1016
1270
|
|
|
1017
|
-
// The overlay is positioned relative to the page, so the scroll offset is
|
|
1018
|
-
// part of the answer.
|
|
1019
1271
|
setPosition({
|
|
1020
|
-
top: placed.top
|
|
1021
|
-
left: placed.left
|
|
1272
|
+
top: placed.top - originTop,
|
|
1273
|
+
left: placed.left - originLeft,
|
|
1022
1274
|
maxHeight: Math.max(0, maxHeight),
|
|
1023
1275
|
maxWidth: Math.max(0, maxWidth),
|
|
1024
1276
|
targetWidth: targetBox.width,
|
|
@@ -1028,25 +1280,19 @@ export function overlayPosition(options: PositionOptions): PositionResult {
|
|
|
1028
1280
|
});
|
|
1029
1281
|
setResolvedAxis(axis);
|
|
1030
1282
|
|
|
1031
|
-
|
|
1032
|
-
if (arrow !== null && arrow !== undefined) {
|
|
1033
|
-
// The same reason, and one more: an arrow is a rotated square, so
|
|
1034
|
-
// `getBoundingClientRect` reports the box the rotation sweeps out — 14.1px
|
|
1035
|
-
// for a 10px arrow — which centred it 2px off its trigger.
|
|
1036
|
-
const arrowBox = layoutSize(arrow);
|
|
1283
|
+
if (arrowBox !== null) {
|
|
1037
1284
|
// Centred on the TARGET, not on the overlay: after a shift the two are
|
|
1038
1285
|
// no longer aligned, and the arrow has to keep pointing at the trigger.
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
}
|
|
1286
|
+
// Kept over the trigger, then inside the overlay clear of its ends.
|
|
1287
|
+
const from = vertical ? targetBox.left - placed.left : targetBox.top - placed.top;
|
|
1288
|
+
const along = vertical ? targetBox.width : targetBox.height;
|
|
1289
|
+
const extent = vertical ? overlayBox.width : height;
|
|
1290
|
+
const centre = clamp(
|
|
1291
|
+
clamp(from + along / 2, from + arrowSize / 2, from + along - arrowSize / 2),
|
|
1292
|
+
arrowSize / 2 + arrowEdge,
|
|
1293
|
+
extent - arrowSize / 2 - arrowEdge,
|
|
1294
|
+
);
|
|
1295
|
+
setArrowOffset(centre - arrowSize / 2);
|
|
1050
1296
|
}
|
|
1051
1297
|
};
|
|
1052
1298
|
|
|
@@ -1077,6 +1323,7 @@ export function overlayPosition(options: PositionOptions): PositionResult {
|
|
|
1077
1323
|
access(options.overlayRef),
|
|
1078
1324
|
access(options.boundaryRef ?? undefined),
|
|
1079
1325
|
access(options.arrowRef ?? undefined),
|
|
1326
|
+
access(options.arrowBoundaryOffset),
|
|
1080
1327
|
access(options.placement),
|
|
1081
1328
|
access(options.offset),
|
|
1082
1329
|
access(options.crossOffset),
|
|
@@ -1173,6 +1420,18 @@ export interface ModalOverlayOptions extends OverlayOptions {
|
|
|
1173
1420
|
isScrollDisabled?: MaybeAccessor<boolean | undefined>;
|
|
1174
1421
|
/** Nothing outside is hidden from assistive technology, and it is not marked modal. */
|
|
1175
1422
|
isNonModal?: MaybeAccessor<boolean | undefined>;
|
|
1423
|
+
/**
|
|
1424
|
+
* Still animating in. The rest of the page is hidden only once it has
|
|
1425
|
+
* arrived: moving a screen reader's cursor into a modal that is still sliding
|
|
1426
|
+
* in scrolls, and on iOS that interrupts the animation. Until then the modal
|
|
1427
|
+
* is only kept visible inside whatever is already hiding the page.
|
|
1428
|
+
*
|
|
1429
|
+
* Moving focus in waits for the same moment, and is the caller's: a focus
|
|
1430
|
+
* scope's `autoFocus`.
|
|
1431
|
+
*
|
|
1432
|
+
* @default false
|
|
1433
|
+
*/
|
|
1434
|
+
isEntering?: MaybeAccessor<boolean | undefined>;
|
|
1176
1435
|
}
|
|
1177
1436
|
|
|
1178
1437
|
export interface ModalOverlayResult extends OverlayResult {
|
|
@@ -1200,9 +1459,13 @@ export function modalOverlay(
|
|
|
1200
1459
|
followOpen(
|
|
1201
1460
|
() =>
|
|
1202
1461
|
state.isOpen() && access(options.isNonModal) !== true
|
|
1203
|
-
? ((access(ref) as Element | null) ?? null)
|
|
1462
|
+
? ([(access(ref) as Element | null) ?? null, access(options.isEntering) === true] as const)
|
|
1204
1463
|
: null,
|
|
1205
|
-
(
|
|
1464
|
+
(open) => {
|
|
1465
|
+
if (open === null || open[0] === null) return undefined;
|
|
1466
|
+
const [element, isEntering] = open;
|
|
1467
|
+
return isEntering ? keepVisible(element) : ariaHideOutside([element]);
|
|
1468
|
+
},
|
|
1206
1469
|
);
|
|
1207
1470
|
|
|
1208
1471
|
return {
|
|
@@ -1212,6 +1475,43 @@ export function modalOverlay(
|
|
|
1212
1475
|
};
|
|
1213
1476
|
}
|
|
1214
1477
|
|
|
1478
|
+
const overlayStrings = new StringDictionary<"dismiss">({
|
|
1479
|
+
"ar-AE": { dismiss: "تجاهل" },
|
|
1480
|
+
"bg-BG": { dismiss: "Отхвърляне" },
|
|
1481
|
+
"cs-CZ": { dismiss: "Odstranit" },
|
|
1482
|
+
"da-DK": { dismiss: "Luk" },
|
|
1483
|
+
"de-DE": { dismiss: "Schließen" },
|
|
1484
|
+
"el-GR": { dismiss: "Απόρριψη" },
|
|
1485
|
+
"en-US": { dismiss: "Dismiss" },
|
|
1486
|
+
"es-ES": { dismiss: "Descartar" },
|
|
1487
|
+
"et-EE": { dismiss: "Lõpeta" },
|
|
1488
|
+
"fi-FI": { dismiss: "Hylkää" },
|
|
1489
|
+
"fr-FR": { dismiss: "Rejeter" },
|
|
1490
|
+
"he-IL": { dismiss: "התעלם" },
|
|
1491
|
+
"hr-HR": { dismiss: "Odbaci" },
|
|
1492
|
+
"hu-HU": { dismiss: "Elutasítás" },
|
|
1493
|
+
"it-IT": { dismiss: "Ignora" },
|
|
1494
|
+
"ja-JP": { dismiss: "閉じる" },
|
|
1495
|
+
"ko-KR": { dismiss: "무시" },
|
|
1496
|
+
"lt-LT": { dismiss: "Atmesti" },
|
|
1497
|
+
"lv-LV": { dismiss: "Nerādīt" },
|
|
1498
|
+
"nb-NO": { dismiss: "Lukk" },
|
|
1499
|
+
"nl-NL": { dismiss: "Negeren" },
|
|
1500
|
+
"pl-PL": { dismiss: "Zignoruj" },
|
|
1501
|
+
"pt-BR": { dismiss: "Descartar" },
|
|
1502
|
+
"pt-PT": { dismiss: "Dispensar" },
|
|
1503
|
+
"ro-RO": { dismiss: "Revocare" },
|
|
1504
|
+
"ru-RU": { dismiss: "Пропустить" },
|
|
1505
|
+
"sk-SK": { dismiss: "Zrušiť" },
|
|
1506
|
+
"sl-SI": { dismiss: "Opusti" },
|
|
1507
|
+
"sr-SP": { dismiss: "Odbaci" },
|
|
1508
|
+
"sv-SE": { dismiss: "Avvisa" },
|
|
1509
|
+
"tr-TR": { dismiss: "Kapat" },
|
|
1510
|
+
"uk-UA": { dismiss: "Скасувати" },
|
|
1511
|
+
"zh-CN": { dismiss: "取消" },
|
|
1512
|
+
"zh-TW": { dismiss: "關閉" },
|
|
1513
|
+
});
|
|
1514
|
+
|
|
1215
1515
|
/**
|
|
1216
1516
|
* A button that closes the overlay, rendered at its end and visible only to a
|
|
1217
1517
|
* screen reader.
|
|
@@ -1220,9 +1520,11 @@ export function modalOverlay(
|
|
|
1220
1520
|
* last element and the next swipe leaves the overlay without closing it.
|
|
1221
1521
|
*/
|
|
1222
1522
|
export function dismissButtonProps(onDismiss: () => void): DOMProps {
|
|
1523
|
+
const message = stringFormatter(overlayStrings);
|
|
1223
1524
|
return {
|
|
1525
|
+
type: "button",
|
|
1224
1526
|
tabIndex: -1,
|
|
1225
|
-
"aria-label": "
|
|
1527
|
+
"aria-label": () => message().format("dismiss"),
|
|
1226
1528
|
style: {
|
|
1227
1529
|
width: "1px",
|
|
1228
1530
|
height: "1px",
|
package/src/platform.ts
CHANGED
|
@@ -25,7 +25,8 @@ function testPlatform(re: RegExp): boolean {
|
|
|
25
25
|
if (typeof window === "undefined" || window.navigator === undefined) return false;
|
|
26
26
|
const data = (window.navigator as Navigator & { userAgentData?: { platform?: string } })
|
|
27
27
|
.userAgentData;
|
|
28
|
-
|
|
28
|
+
// Chromium can report an empty platform here; the legacy one still answers.
|
|
29
|
+
return re.test(data?.platform || window.navigator.platform);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
/**
|