@tamagui/react-native-web-lite 1.129.4 → 1.129.5-1751174117974

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.
@@ -1,78 +0,0 @@
1
- import * as React from "react";
2
- import { StyleSheet, UIManager, canUseDOM } from "@tamagui/react-native-web-internals";
3
- import createElement from "../createElement/index.native.js";
4
- import View from "../View";
5
- var FocusBracket = function () {
6
- return createElement("div", {
7
- accessibilityRole: "none",
8
- tabIndex: 0,
9
- style: styles.focusBracket
10
- });
11
- };
12
- function attemptFocus(element) {
13
- if (!canUseDOM) return !1;
14
- try {
15
- element.focus();
16
- } catch {}
17
- return document.activeElement === element;
18
- }
19
- function focusFirstDescendant(element) {
20
- for (var i = 0; i < element.childNodes.length; i++) {
21
- var child = element.childNodes[i];
22
- if (attemptFocus(child) || focusFirstDescendant(child)) return !0;
23
- }
24
- return !1;
25
- }
26
- function focusLastDescendant(element) {
27
- for (var i = element.childNodes.length - 1; i >= 0; i--) {
28
- var child = element.childNodes[i];
29
- if (attemptFocus(child) || focusLastDescendant(child)) return !0;
30
- }
31
- return !1;
32
- }
33
- var ModalFocusTrap = function (_ref) {
34
- var active = _ref.active,
35
- children = _ref.children,
36
- trapElementRef = React.useRef(),
37
- focusRef = React.useRef({
38
- trapFocusInProgress: !1,
39
- lastFocusedElement: null
40
- });
41
- return React.useEffect(function () {
42
- if (canUseDOM) {
43
- var trapFocus = function () {
44
- if (!(trapElementRef.current == null || focusRef.current.trapFocusInProgress || !active)) {
45
- try {
46
- if (focusRef.current.trapFocusInProgress = !0, document.activeElement instanceof Node && !trapElementRef.current.contains(document.activeElement)) {
47
- var hasFocused = focusFirstDescendant(trapElementRef.current);
48
- focusRef.current.lastFocusedElement === document.activeElement && (hasFocused = focusLastDescendant(trapElementRef.current)), !hasFocused && trapElementRef.current != null && document.activeElement && UIManager.focus(trapElementRef.current);
49
- }
50
- } finally {
51
- focusRef.current.trapFocusInProgress = !1;
52
- }
53
- focusRef.current.lastFocusedElement = document.activeElement;
54
- }
55
- };
56
- return trapFocus(), document.addEventListener("focus", trapFocus, !0), function () {
57
- return document.removeEventListener("focus", trapFocus, !0);
58
- };
59
- }
60
- }, [active]), React.useEffect(function () {
61
- if (canUseDOM) {
62
- var lastFocusedElementOutsideTrap = document.activeElement;
63
- return function () {
64
- lastFocusedElementOutsideTrap && document.contains(lastFocusedElementOutsideTrap) && UIManager.focus(lastFocusedElementOutsideTrap);
65
- };
66
- }
67
- }, []), /* @__PURE__ */React.createElement(React.Fragment, null, /* @__PURE__ */React.createElement(FocusBracket, null), /* @__PURE__ */React.createElement(View, {
68
- ref: trapElementRef
69
- }, children), /* @__PURE__ */React.createElement(FocusBracket, null));
70
- },
71
- ModalFocusTrap_default = ModalFocusTrap,
72
- styles = StyleSheet.create({
73
- focusBracket: {
74
- outlineStyle: "none"
75
- }
76
- });
77
- export { ModalFocusTrap_default as default };
78
- //# sourceMappingURL=ModalFocusTrap.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","StyleSheet","UIManager","canUseDOM","createElement","View","FocusBracket","accessibilityRole","tabIndex","style","styles","focusBracket","attemptFocus","element","focus","document","activeElement","focusFirstDescendant","i","childNodes","length","child","focusLastDescendant","ModalFocusTrap","_ref","active","children","trapElementRef","useRef","focusRef","trapFocusInProgress","lastFocusedElement","useEffect","trapFocus","current","Node","contains","hasFocused","addEventListener","removeEventListener","lastFocusedElementOutsideTrap","Fragment","ref","ModalFocusTrap_default","create","outlineStyle","default"],"sources":["../../../src/Modal/ModalFocusTrap.js"],"sourcesContent":[null],"mappings":"AASA,YAAYA,KAAA,MAAW;AACvB,SAASC,UAAA,EAAYC,SAAA,EAAWC,SAAA,QAAiB;AAEjD,OAAOC,aAAA,MAAmB;AAC1B,OAAOC,IAAA,MAAU;AAUjB,IAAIC,YAAA,GAAe,SAAAA,CAAA,EACV;EACL,OAAAF,aAAmB;IACnBG,iBAAU;IACVC,QAAO;IACRC,KAAA,EAAAC,M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T,UAAA,CAAA2C,MAAA;IAAAjC,YACF;MACckC,YAAA;IAChB;EACF;AAG+B,SACfF,sBACE,IAAAG,OAAA","ignoreList":[]}
@@ -1,163 +0,0 @@
1
- /**
2
- * Copyright (c) Nicolas Gallagher.
3
- * Copyright (c) Meta Platforms, Inc. and affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- *
8
- *
9
- */
10
- import * as React from 'react'
11
- import { StyleSheet, UIManager, canUseDOM } from '@tamagui/react-native-web-internals'
12
-
13
- import createElement from '../createElement/index'
14
- import View from '../View'
15
-
16
- /**
17
- * This Component is used to "wrap" the modal we're opening
18
- * so that changing focus via tab will never leave the document.
19
- *
20
- * This allows us to properly trap the focus within a modal
21
- * even if the modal is at the start or end of a document.
22
- */
23
-
24
- var FocusBracket = () => {
25
- return createElement('div', {
26
- accessibilityRole: 'none',
27
- tabIndex: 0,
28
- style: styles.focusBracket,
29
- })
30
- }
31
-
32
- function attemptFocus(element) {
33
- if (!canUseDOM) {
34
- return false
35
- }
36
-
37
- try {
38
- element.focus()
39
- } catch (e) {
40
- // Do nothing
41
- }
42
-
43
- return document.activeElement === element
44
- }
45
-
46
- function focusFirstDescendant(element) {
47
- for (var i = 0; i < element.childNodes.length; i++) {
48
- var child = element.childNodes[i]
49
-
50
- if (attemptFocus(child) || focusFirstDescendant(child)) {
51
- return true
52
- }
53
- }
54
-
55
- return false
56
- }
57
-
58
- function focusLastDescendant(element) {
59
- for (var i = element.childNodes.length - 1; i >= 0; i--) {
60
- var child = element.childNodes[i]
61
-
62
- if (attemptFocus(child) || focusLastDescendant(child)) {
63
- return true
64
- }
65
- }
66
-
67
- return false
68
- }
69
-
70
- var ModalFocusTrap = (_ref) => {
71
- var active = _ref.active,
72
- children = _ref.children
73
- var trapElementRef = React.useRef()
74
- var focusRef = React.useRef({
75
- trapFocusInProgress: false,
76
- lastFocusedElement: null,
77
- })
78
- React.useEffect(() => {
79
- if (canUseDOM) {
80
- var trapFocus = () => {
81
- // We should not trap focus if:
82
- // - The modal hasn't fully initialized with an HTMLElement ref
83
- // - Focus is already in the process of being trapped (e.g., we're refocusing)
84
- // - isTrapActive prop being falsey tells us to do nothing
85
- if (
86
- trapElementRef.current == null ||
87
- focusRef.current.trapFocusInProgress ||
88
- !active
89
- ) {
90
- return
91
- }
92
-
93
- try {
94
- focusRef.current.trapFocusInProgress = true
95
-
96
- if (
97
- document.activeElement instanceof Node &&
98
- !trapElementRef.current.contains(document.activeElement)
99
- ) {
100
- // To handle keyboard focusing we can make an assumption here.
101
- // If you're tabbing through the focusable elements, the previously
102
- // active element will either be the first or the last.
103
- // If the previously selected element is the "first" descendant
104
- // and we're leaving it - this means that we should be looping
105
- // around to the other side of the modal.
106
- var hasFocused = focusFirstDescendant(trapElementRef.current)
107
-
108
- if (focusRef.current.lastFocusedElement === document.activeElement) {
109
- hasFocused = focusLastDescendant(trapElementRef.current)
110
- } // If we couldn't focus a new element then we need to focus onto the trap target
111
-
112
- if (!hasFocused && trapElementRef.current != null && document.activeElement) {
113
- UIManager.focus(trapElementRef.current)
114
- }
115
- }
116
- } finally {
117
- focusRef.current.trapFocusInProgress = false
118
- }
119
-
120
- focusRef.current.lastFocusedElement = document.activeElement
121
- } // Call the trapFocus callback at least once when this modal has been activated.
122
-
123
- trapFocus()
124
- document.addEventListener('focus', trapFocus, true)
125
- return () => document.removeEventListener('focus', trapFocus, true)
126
- }
127
- }, [active]) // To be fully compliant with WCAG we need to refocus element that triggered opening modal
128
- // after closing it
129
-
130
- React.useEffect(function () {
131
- if (canUseDOM) {
132
- var lastFocusedElementOutsideTrap = document.activeElement
133
- return function () {
134
- if (
135
- lastFocusedElementOutsideTrap &&
136
- document.contains(lastFocusedElementOutsideTrap)
137
- ) {
138
- UIManager.focus(lastFocusedElementOutsideTrap)
139
- }
140
- }
141
- }
142
- }, [])
143
- return /*#__PURE__*/ React.createElement(
144
- React.Fragment,
145
- null,
146
- /*#__PURE__*/ React.createElement(FocusBracket, null),
147
- /*#__PURE__*/ React.createElement(
148
- View,
149
- {
150
- ref: trapElementRef,
151
- },
152
- children
153
- ),
154
- /*#__PURE__*/ React.createElement(FocusBracket, null)
155
- )
156
- }
157
-
158
- export default ModalFocusTrap
159
- var styles = StyleSheet.create({
160
- focusBracket: {
161
- outlineStyle: 'none',
162
- },
163
- })