carbon-react 125.1.0 → 125.2.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/esm/components/flat-table/flat-table.component.js +14 -4
- package/esm/components/flat-table/flat-table.style.d.ts +1 -0
- package/esm/components/flat-table/flat-table.style.js +14 -23
- package/esm/components/popover-container/popover-container.component.js +33 -17
- package/esm/components/popover-container/popover-container.style.js +4 -0
- package/lib/components/flat-table/flat-table.component.js +14 -4
- package/lib/components/flat-table/flat-table.style.d.ts +1 -0
- package/lib/components/flat-table/flat-table.style.js +14 -23
- package/lib/components/popover-container/popover-container.component.js +33 -17
- package/lib/components/popover-container/popover-container.style.js +4 -0
- package/package.json +1 -1
|
@@ -27,10 +27,12 @@ export const FlatTable = ({
|
|
|
27
27
|
}) => {
|
|
28
28
|
const wrapperRef = useRef(null);
|
|
29
29
|
const tableRef = useRef(null);
|
|
30
|
+
const container = useRef(null);
|
|
30
31
|
const [hasVerticalScrollbar, setHasVerticalScrollbar] = useState(false);
|
|
31
32
|
const [hasHorizontalScrollbar, setHasHorizontalScrollbar] = useState(false);
|
|
32
33
|
const [firstColRowSpanIndex, setFirstColRowSpanIndex] = useState(-1);
|
|
33
34
|
const [lastColRowSpanIndex, setLastColRowSpanIndex] = useState(-1);
|
|
35
|
+
const [focused, setFocused] = useState(false);
|
|
34
36
|
const addDefaultHeight = !height && (hasStickyHead || hasStickyFooter);
|
|
35
37
|
const tableStylingProps = {
|
|
36
38
|
caption,
|
|
@@ -92,12 +94,12 @@ export const FlatTable = ({
|
|
|
92
94
|
});
|
|
93
95
|
const handleKeyDown = ev => {
|
|
94
96
|
const focusableElements = tableRef.current?.querySelectorAll(FOCUSABLE_ROW_AND_CELL_QUERY);
|
|
97
|
+
const focusableElementsArray = Array.from(focusableElements || /* istanbul ignore next */[]);
|
|
95
98
|
|
|
96
99
|
/* istanbul ignore if */
|
|
97
|
-
if (!
|
|
100
|
+
if (!focusableElementsArray.length) {
|
|
98
101
|
return;
|
|
99
102
|
}
|
|
100
|
-
const focusableElementsArray = Array.from(focusableElements);
|
|
101
103
|
const currentFocusIndex = focusableElementsArray.findIndex(el => el === document.activeElement);
|
|
102
104
|
if (Events.isDownKey(ev)) {
|
|
103
105
|
ev.preventDefault();
|
|
@@ -144,7 +146,6 @@ export const FlatTable = ({
|
|
|
144
146
|
display: "flex",
|
|
145
147
|
flexDirection: "column",
|
|
146
148
|
justifyContent: hasStickyFooter || height ? "space-between" : undefined,
|
|
147
|
-
tabIndex: 0,
|
|
148
149
|
role: "region",
|
|
149
150
|
overflowX: width ? "hidden" : undefined,
|
|
150
151
|
width: width,
|
|
@@ -154,8 +155,17 @@ export const FlatTable = ({
|
|
|
154
155
|
footer: !!footer,
|
|
155
156
|
firstColRowSpanIndex: firstColRowSpanIndex,
|
|
156
157
|
lastColRowSpanIndex: lastColRowSpanIndex,
|
|
157
|
-
onKeyDown: handleKeyDown
|
|
158
|
+
onKeyDown: handleKeyDown,
|
|
159
|
+
isFocused: focused
|
|
158
160
|
}, rest), /*#__PURE__*/React.createElement(StyledTableContainer, {
|
|
161
|
+
ref: container,
|
|
162
|
+
onFocus: () => {
|
|
163
|
+
if (container.current === document.activeElement) {
|
|
164
|
+
setFocused(true);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
onBlur: () => setFocused(false),
|
|
168
|
+
tabIndex: 0,
|
|
159
169
|
overflowX: overflowX,
|
|
160
170
|
width: width
|
|
161
171
|
}, /*#__PURE__*/React.createElement(StyledFlatTable, _extends({
|
|
@@ -9,6 +9,7 @@ interface StyledFlatTableWrapperProps extends Pick<FlatTableProps, "hasStickyFoo
|
|
|
9
9
|
hasVerticalScrollbar: boolean;
|
|
10
10
|
lastColRowSpanIndex: number;
|
|
11
11
|
firstColRowSpanIndex: number;
|
|
12
|
+
isFocused: boolean;
|
|
12
13
|
}
|
|
13
14
|
declare const StyledFlatTableWrapper: import("styled-components").StyledComponent<"div", any, import("../box").BoxProps & StyledFlatTableWrapperProps, never>;
|
|
14
15
|
declare const StyledFlatTableFooter: import("styled-components").StyledComponent<"div", any, Pick<FlatTableProps, "hasStickyFooter">, never>;
|
|
@@ -25,6 +25,10 @@ const StyledTableContainer = styled.div`
|
|
|
25
25
|
|
|
26
26
|
${overflowX && `overflow-x: ${overflowX};`}
|
|
27
27
|
`}
|
|
28
|
+
|
|
29
|
+
:focus {
|
|
30
|
+
outline: none;
|
|
31
|
+
}
|
|
28
32
|
`;
|
|
29
33
|
const StyledFlatTable = styled.table`
|
|
30
34
|
border-collapse: separate;
|
|
@@ -106,35 +110,22 @@ const StyledFlatTableWrapper = styled(StyledBox)`
|
|
|
106
110
|
|
|
107
111
|
${({
|
|
108
112
|
isInSidebar,
|
|
109
|
-
theme
|
|
113
|
+
theme,
|
|
114
|
+
isFocused
|
|
110
115
|
}) => css`
|
|
111
116
|
box-sizing: border-box;
|
|
112
117
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
${theme.focusRedesignOptOut && /* istanbul ignore next */
|
|
118
|
+
/* istanbul ignore next */
|
|
119
|
+
${theme.focusRedesignOptOut && isFocused && /* istanbul ignore next */
|
|
116
120
|
css`
|
|
117
|
-
|
|
121
|
+
${oldFocusStyling}
|
|
122
|
+
`}
|
|
118
123
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
:focus-visible {
|
|
124
|
-
${oldFocusStyling}
|
|
125
|
-
}
|
|
126
|
-
`}
|
|
127
|
-
|
|
128
|
-
${!theme.focusRedesignOptOut && css`
|
|
129
|
-
${addFocusStyling()}
|
|
130
|
-
:not(:focus-visible) {
|
|
131
|
-
outline: none;
|
|
132
|
-
box-shadow: none;
|
|
133
|
-
}
|
|
134
|
-
`}
|
|
135
|
-
}
|
|
124
|
+
${!theme.focusRedesignOptOut && isFocused && css`
|
|
125
|
+
${addFocusStyling()}
|
|
126
|
+
`}
|
|
136
127
|
|
|
137
|
-
${isInSidebar ? "min-width: fit-content" :
|
|
128
|
+
${isInSidebar ? "min-width: fit-content;" : ""}
|
|
138
129
|
`}
|
|
139
130
|
|
|
140
131
|
${({
|
|
@@ -11,6 +11,8 @@ import createGuid from "../../__internal__/utils/helpers/guid";
|
|
|
11
11
|
import { filterStyledSystemPaddingProps } from "../../style/utils";
|
|
12
12
|
import useClickAwayListener from "../../hooks/__internal__/useClickAwayListener";
|
|
13
13
|
import Events from "../../__internal__/utils/helpers/events";
|
|
14
|
+
import FocusTrap from "../../__internal__/focus-trap";
|
|
15
|
+
import { ModalContext } from "../modal";
|
|
14
16
|
export const renderOpen = ({
|
|
15
17
|
tabIndex,
|
|
16
18
|
onClick,
|
|
@@ -81,19 +83,20 @@ export const PopoverContainer = ({
|
|
|
81
83
|
const popoverContainerId = title ? `PopoverContainer_${guid.current}` : undefined;
|
|
82
84
|
const isOpen = isControlled ? open : isOpenInternal;
|
|
83
85
|
const reduceMotion = !useMediaQuery("screen and (prefers-reduced-motion: no-preference)");
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
if (isOpen && closeButtonRef.current) setTimeout(() => closeButtonRef.current?.focus(), 0);
|
|
86
|
-
}, [isOpen]);
|
|
87
86
|
const closePopover = useCallback(ev => {
|
|
88
|
-
if (!isControlled) setIsOpenInternal(
|
|
87
|
+
if (!isControlled) setIsOpenInternal(false);
|
|
89
88
|
if (onClose) onClose(ev);
|
|
90
|
-
if (isOpen && openButtonRef.current)
|
|
89
|
+
if (isOpen && openButtonRef.current) {
|
|
90
|
+
openButtonRef.current.focus();
|
|
91
|
+
}
|
|
91
92
|
}, [isControlled, isOpen, onClose]);
|
|
92
93
|
const handleEscKey = useCallback(ev => {
|
|
93
94
|
const eventIsFromSelectInput = Events.composedPath(ev).find(element => {
|
|
94
95
|
return element instanceof HTMLElement && element.getAttribute("data-element") === "input" && element.getAttribute("aria-expanded") === "true";
|
|
95
96
|
});
|
|
96
|
-
if (!eventIsFromSelectInput && Events.isEscKey(ev))
|
|
97
|
+
if (!eventIsFromSelectInput && Events.isEscKey(ev)) {
|
|
98
|
+
closePopover(ev);
|
|
99
|
+
}
|
|
97
100
|
}, [closePopover]);
|
|
98
101
|
useEffect(() => {
|
|
99
102
|
document.addEventListener("keydown", handleEscKey);
|
|
@@ -113,7 +116,7 @@ export const PopoverContainer = ({
|
|
|
113
116
|
closePopover(e);
|
|
114
117
|
};
|
|
115
118
|
const renderOpenComponentProps = {
|
|
116
|
-
tabIndex:
|
|
119
|
+
tabIndex: 0,
|
|
117
120
|
"aria-expanded": isOpen,
|
|
118
121
|
"aria-haspopup": "dialog",
|
|
119
122
|
isOpen,
|
|
@@ -135,12 +138,8 @@ export const PopoverContainer = ({
|
|
|
135
138
|
if (onClose && isOpen) onClose(e);
|
|
136
139
|
};
|
|
137
140
|
const handleClick = useClickAwayListener(handleClickAway, "mousedown");
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
onMouseDown: handleClick
|
|
141
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
142
|
-
ref: popoverReference
|
|
143
|
-
}, renderOpenComponent(renderOpenComponentProps)), /*#__PURE__*/React.createElement(Transition, {
|
|
141
|
+
const [isAnimationComplete, setIsAnimationComplete] = useState(false);
|
|
142
|
+
const popover = /*#__PURE__*/React.createElement(Transition, {
|
|
144
143
|
in: isOpen,
|
|
145
144
|
timeout: {
|
|
146
145
|
exit: 300
|
|
@@ -148,11 +147,14 @@ export const PopoverContainer = ({
|
|
|
148
147
|
appear: true,
|
|
149
148
|
mountOnEnter: true,
|
|
150
149
|
unmountOnExit: true,
|
|
151
|
-
nodeRef: popoverContentNodeRef
|
|
150
|
+
nodeRef: popoverContentNodeRef,
|
|
151
|
+
onEntered: shouldCoverButton ? /* istanbul ignore next */() => setIsAnimationComplete(true) : undefined,
|
|
152
|
+
onExiting: shouldCoverButton ? /* istanbul ignore next */() => setIsAnimationComplete(false) : undefined
|
|
152
153
|
}, state => isOpen && /*#__PURE__*/React.createElement(Popover, _extends({
|
|
153
|
-
|
|
154
|
+
disablePortal: true,
|
|
154
155
|
reference: popoverReference,
|
|
155
|
-
placement: position === "right" ? "bottom-start" : "bottom-end"
|
|
156
|
+
placement: position === "right" ? "bottom-start" : "bottom-end",
|
|
157
|
+
popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute"
|
|
156
158
|
}, shouldCoverButton && {
|
|
157
159
|
middleware: popoverMiddleware
|
|
158
160
|
}), /*#__PURE__*/React.createElement(PopoverContainerContentStyle, _extends({
|
|
@@ -164,10 +166,24 @@ export const PopoverContainer = ({
|
|
|
164
166
|
"aria-describedby": ariaDescribedBy,
|
|
165
167
|
p: "16px 24px",
|
|
166
168
|
ref: popoverContentNodeRef,
|
|
169
|
+
tabIndex: shouldCoverButton ? -1 : undefined,
|
|
167
170
|
disableAnimation: disableAnimation || reduceMotion
|
|
168
171
|
}, filterStyledSystemPaddingProps(rest)), /*#__PURE__*/React.createElement(PopoverContainerHeaderStyle, null, /*#__PURE__*/React.createElement(PopoverContainerTitleStyle, {
|
|
169
172
|
id: popoverContainerId,
|
|
170
173
|
"data-element": "popover-container-title"
|
|
171
|
-
}, title), renderCloseComponent(renderCloseComponentProps)), children)))
|
|
174
|
+
}, title), renderCloseComponent(renderCloseComponentProps)), children)));
|
|
175
|
+
return /*#__PURE__*/React.createElement(PopoverContainerWrapperStyle, {
|
|
176
|
+
"data-component": "popover-container",
|
|
177
|
+
onMouseDown: handleClick
|
|
178
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
179
|
+
ref: popoverReference
|
|
180
|
+
}, renderOpenComponent(renderOpenComponentProps)), shouldCoverButton ? /*#__PURE__*/React.createElement(ModalContext.Provider, {
|
|
181
|
+
value: {
|
|
182
|
+
isAnimationComplete
|
|
183
|
+
}
|
|
184
|
+
}, /*#__PURE__*/React.createElement(FocusTrap, {
|
|
185
|
+
wrapperRef: popoverContentNodeRef,
|
|
186
|
+
isOpen: isOpen
|
|
187
|
+
}, popover)) : popover);
|
|
172
188
|
};
|
|
173
189
|
export default PopoverContainer;
|
|
@@ -36,10 +36,12 @@ const FlatTable = ({
|
|
|
36
36
|
}) => {
|
|
37
37
|
const wrapperRef = (0, _react.useRef)(null);
|
|
38
38
|
const tableRef = (0, _react.useRef)(null);
|
|
39
|
+
const container = (0, _react.useRef)(null);
|
|
39
40
|
const [hasVerticalScrollbar, setHasVerticalScrollbar] = (0, _react.useState)(false);
|
|
40
41
|
const [hasHorizontalScrollbar, setHasHorizontalScrollbar] = (0, _react.useState)(false);
|
|
41
42
|
const [firstColRowSpanIndex, setFirstColRowSpanIndex] = (0, _react.useState)(-1);
|
|
42
43
|
const [lastColRowSpanIndex, setLastColRowSpanIndex] = (0, _react.useState)(-1);
|
|
44
|
+
const [focused, setFocused] = (0, _react.useState)(false);
|
|
43
45
|
const addDefaultHeight = !height && (hasStickyHead || hasStickyFooter);
|
|
44
46
|
const tableStylingProps = {
|
|
45
47
|
caption,
|
|
@@ -101,12 +103,12 @@ const FlatTable = ({
|
|
|
101
103
|
});
|
|
102
104
|
const handleKeyDown = ev => {
|
|
103
105
|
const focusableElements = tableRef.current?.querySelectorAll(FOCUSABLE_ROW_AND_CELL_QUERY);
|
|
106
|
+
const focusableElementsArray = Array.from(focusableElements || /* istanbul ignore next */[]);
|
|
104
107
|
|
|
105
108
|
/* istanbul ignore if */
|
|
106
|
-
if (!
|
|
109
|
+
if (!focusableElementsArray.length) {
|
|
107
110
|
return;
|
|
108
111
|
}
|
|
109
|
-
const focusableElementsArray = Array.from(focusableElements);
|
|
110
112
|
const currentFocusIndex = focusableElementsArray.findIndex(el => el === document.activeElement);
|
|
111
113
|
if (_events.default.isDownKey(ev)) {
|
|
112
114
|
ev.preventDefault();
|
|
@@ -153,7 +155,6 @@ const FlatTable = ({
|
|
|
153
155
|
display: "flex",
|
|
154
156
|
flexDirection: "column",
|
|
155
157
|
justifyContent: hasStickyFooter || height ? "space-between" : undefined,
|
|
156
|
-
tabIndex: 0,
|
|
157
158
|
role: "region",
|
|
158
159
|
overflowX: width ? "hidden" : undefined,
|
|
159
160
|
width: width,
|
|
@@ -163,8 +164,17 @@ const FlatTable = ({
|
|
|
163
164
|
footer: !!footer,
|
|
164
165
|
firstColRowSpanIndex: firstColRowSpanIndex,
|
|
165
166
|
lastColRowSpanIndex: lastColRowSpanIndex,
|
|
166
|
-
onKeyDown: handleKeyDown
|
|
167
|
+
onKeyDown: handleKeyDown,
|
|
168
|
+
isFocused: focused
|
|
167
169
|
}, rest), /*#__PURE__*/_react.default.createElement(_flatTable.StyledTableContainer, {
|
|
170
|
+
ref: container,
|
|
171
|
+
onFocus: () => {
|
|
172
|
+
if (container.current === document.activeElement) {
|
|
173
|
+
setFocused(true);
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
onBlur: () => setFocused(false),
|
|
177
|
+
tabIndex: 0,
|
|
168
178
|
overflowX: overflowX,
|
|
169
179
|
width: width
|
|
170
180
|
}, /*#__PURE__*/_react.default.createElement(_flatTable.StyledFlatTable, _extends({
|
|
@@ -9,6 +9,7 @@ interface StyledFlatTableWrapperProps extends Pick<FlatTableProps, "hasStickyFoo
|
|
|
9
9
|
hasVerticalScrollbar: boolean;
|
|
10
10
|
lastColRowSpanIndex: number;
|
|
11
11
|
firstColRowSpanIndex: number;
|
|
12
|
+
isFocused: boolean;
|
|
12
13
|
}
|
|
13
14
|
declare const StyledFlatTableWrapper: import("styled-components").StyledComponent<"div", any, import("../box").BoxProps & StyledFlatTableWrapperProps, never>;
|
|
14
15
|
declare const StyledFlatTableFooter: import("styled-components").StyledComponent<"div", any, Pick<FlatTableProps, "hasStickyFooter">, never>;
|
|
@@ -34,6 +34,10 @@ const StyledTableContainer = exports.StyledTableContainer = _styledComponents.de
|
|
|
34
34
|
|
|
35
35
|
${overflowX && `overflow-x: ${overflowX};`}
|
|
36
36
|
`}
|
|
37
|
+
|
|
38
|
+
:focus {
|
|
39
|
+
outline: none;
|
|
40
|
+
}
|
|
37
41
|
`;
|
|
38
42
|
const StyledFlatTable = exports.StyledFlatTable = _styledComponents.default.table`
|
|
39
43
|
border-collapse: separate;
|
|
@@ -115,35 +119,22 @@ const StyledFlatTableWrapper = exports.StyledFlatTableWrapper = (0, _styledCompo
|
|
|
115
119
|
|
|
116
120
|
${({
|
|
117
121
|
isInSidebar,
|
|
118
|
-
theme
|
|
122
|
+
theme,
|
|
123
|
+
isFocused
|
|
119
124
|
}) => (0, _styledComponents.css)`
|
|
120
125
|
box-sizing: border-box;
|
|
121
126
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
${theme.focusRedesignOptOut && /* istanbul ignore next */
|
|
127
|
+
/* istanbul ignore next */
|
|
128
|
+
${theme.focusRedesignOptOut && isFocused && /* istanbul ignore next */
|
|
125
129
|
(0, _styledComponents.css)`
|
|
126
|
-
|
|
130
|
+
${oldFocusStyling}
|
|
131
|
+
`}
|
|
127
132
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
:focus-visible {
|
|
133
|
-
${oldFocusStyling}
|
|
134
|
-
}
|
|
135
|
-
`}
|
|
136
|
-
|
|
137
|
-
${!theme.focusRedesignOptOut && (0, _styledComponents.css)`
|
|
138
|
-
${(0, _addFocusStyling.default)()}
|
|
139
|
-
:not(:focus-visible) {
|
|
140
|
-
outline: none;
|
|
141
|
-
box-shadow: none;
|
|
142
|
-
}
|
|
143
|
-
`}
|
|
144
|
-
}
|
|
133
|
+
${!theme.focusRedesignOptOut && isFocused && (0, _styledComponents.css)`
|
|
134
|
+
${(0, _addFocusStyling.default)()}
|
|
135
|
+
`}
|
|
145
136
|
|
|
146
|
-
${isInSidebar ? "min-width: fit-content" :
|
|
137
|
+
${isInSidebar ? "min-width: fit-content;" : ""}
|
|
147
138
|
`}
|
|
148
139
|
|
|
149
140
|
${({
|
|
@@ -16,6 +16,8 @@ var _guid = _interopRequireDefault(require("../../__internal__/utils/helpers/gui
|
|
|
16
16
|
var _utils = require("../../style/utils");
|
|
17
17
|
var _useClickAwayListener = _interopRequireDefault(require("../../hooks/__internal__/useClickAwayListener"));
|
|
18
18
|
var _events = _interopRequireDefault(require("../../__internal__/utils/helpers/events"));
|
|
19
|
+
var _focusTrap = _interopRequireDefault(require("../../__internal__/focus-trap"));
|
|
20
|
+
var _modal = require("../modal");
|
|
19
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
22
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
23
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -92,19 +94,20 @@ const PopoverContainer = ({
|
|
|
92
94
|
const popoverContainerId = title ? `PopoverContainer_${guid.current}` : undefined;
|
|
93
95
|
const isOpen = isControlled ? open : isOpenInternal;
|
|
94
96
|
const reduceMotion = !(0, _useMediaQuery.default)("screen and (prefers-reduced-motion: no-preference)");
|
|
95
|
-
(0, _react.useEffect)(() => {
|
|
96
|
-
if (isOpen && closeButtonRef.current) setTimeout(() => closeButtonRef.current?.focus(), 0);
|
|
97
|
-
}, [isOpen]);
|
|
98
97
|
const closePopover = (0, _react.useCallback)(ev => {
|
|
99
|
-
if (!isControlled) setIsOpenInternal(
|
|
98
|
+
if (!isControlled) setIsOpenInternal(false);
|
|
100
99
|
if (onClose) onClose(ev);
|
|
101
|
-
if (isOpen && openButtonRef.current)
|
|
100
|
+
if (isOpen && openButtonRef.current) {
|
|
101
|
+
openButtonRef.current.focus();
|
|
102
|
+
}
|
|
102
103
|
}, [isControlled, isOpen, onClose]);
|
|
103
104
|
const handleEscKey = (0, _react.useCallback)(ev => {
|
|
104
105
|
const eventIsFromSelectInput = _events.default.composedPath(ev).find(element => {
|
|
105
106
|
return element instanceof HTMLElement && element.getAttribute("data-element") === "input" && element.getAttribute("aria-expanded") === "true";
|
|
106
107
|
});
|
|
107
|
-
if (!eventIsFromSelectInput && _events.default.isEscKey(ev))
|
|
108
|
+
if (!eventIsFromSelectInput && _events.default.isEscKey(ev)) {
|
|
109
|
+
closePopover(ev);
|
|
110
|
+
}
|
|
108
111
|
}, [closePopover]);
|
|
109
112
|
(0, _react.useEffect)(() => {
|
|
110
113
|
document.addEventListener("keydown", handleEscKey);
|
|
@@ -124,7 +127,7 @@ const PopoverContainer = ({
|
|
|
124
127
|
closePopover(e);
|
|
125
128
|
};
|
|
126
129
|
const renderOpenComponentProps = {
|
|
127
|
-
tabIndex:
|
|
130
|
+
tabIndex: 0,
|
|
128
131
|
"aria-expanded": isOpen,
|
|
129
132
|
"aria-haspopup": "dialog",
|
|
130
133
|
isOpen,
|
|
@@ -146,12 +149,8 @@ const PopoverContainer = ({
|
|
|
146
149
|
if (onClose && isOpen) onClose(e);
|
|
147
150
|
};
|
|
148
151
|
const handleClick = (0, _useClickAwayListener.default)(handleClickAway, "mousedown");
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
onMouseDown: handleClick
|
|
152
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
153
|
-
ref: popoverReference
|
|
154
|
-
}, renderOpenComponent(renderOpenComponentProps)), /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.Transition, {
|
|
152
|
+
const [isAnimationComplete, setIsAnimationComplete] = (0, _react.useState)(false);
|
|
153
|
+
const popover = /*#__PURE__*/_react.default.createElement(_reactTransitionGroup.Transition, {
|
|
155
154
|
in: isOpen,
|
|
156
155
|
timeout: {
|
|
157
156
|
exit: 300
|
|
@@ -159,11 +158,14 @@ const PopoverContainer = ({
|
|
|
159
158
|
appear: true,
|
|
160
159
|
mountOnEnter: true,
|
|
161
160
|
unmountOnExit: true,
|
|
162
|
-
nodeRef: popoverContentNodeRef
|
|
161
|
+
nodeRef: popoverContentNodeRef,
|
|
162
|
+
onEntered: shouldCoverButton ? /* istanbul ignore next */() => setIsAnimationComplete(true) : undefined,
|
|
163
|
+
onExiting: shouldCoverButton ? /* istanbul ignore next */() => setIsAnimationComplete(false) : undefined
|
|
163
164
|
}, state => isOpen && /*#__PURE__*/_react.default.createElement(_popover.default, _extends({
|
|
164
|
-
|
|
165
|
+
disablePortal: true,
|
|
165
166
|
reference: popoverReference,
|
|
166
|
-
placement: position === "right" ? "bottom-start" : "bottom-end"
|
|
167
|
+
placement: position === "right" ? "bottom-start" : "bottom-end",
|
|
168
|
+
popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute"
|
|
167
169
|
}, shouldCoverButton && {
|
|
168
170
|
middleware: popoverMiddleware
|
|
169
171
|
}), /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerContentStyle, _extends({
|
|
@@ -175,11 +177,25 @@ const PopoverContainer = ({
|
|
|
175
177
|
"aria-describedby": ariaDescribedBy,
|
|
176
178
|
p: "16px 24px",
|
|
177
179
|
ref: popoverContentNodeRef,
|
|
180
|
+
tabIndex: shouldCoverButton ? -1 : undefined,
|
|
178
181
|
disableAnimation: disableAnimation || reduceMotion
|
|
179
182
|
}, (0, _utils.filterStyledSystemPaddingProps)(rest)), /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerHeaderStyle, null, /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerTitleStyle, {
|
|
180
183
|
id: popoverContainerId,
|
|
181
184
|
"data-element": "popover-container-title"
|
|
182
|
-
}, title), renderCloseComponent(renderCloseComponentProps)), children)))
|
|
185
|
+
}, title), renderCloseComponent(renderCloseComponentProps)), children)));
|
|
186
|
+
return /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerWrapperStyle, {
|
|
187
|
+
"data-component": "popover-container",
|
|
188
|
+
onMouseDown: handleClick
|
|
189
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
190
|
+
ref: popoverReference
|
|
191
|
+
}, renderOpenComponent(renderOpenComponentProps)), shouldCoverButton ? /*#__PURE__*/_react.default.createElement(_modal.ModalContext.Provider, {
|
|
192
|
+
value: {
|
|
193
|
+
isAnimationComplete
|
|
194
|
+
}
|
|
195
|
+
}, /*#__PURE__*/_react.default.createElement(_focusTrap.default, {
|
|
196
|
+
wrapperRef: popoverContentNodeRef,
|
|
197
|
+
isOpen: isOpen
|
|
198
|
+
}, popover)) : popover);
|
|
183
199
|
};
|
|
184
200
|
exports.PopoverContainer = PopoverContainer;
|
|
185
201
|
var _default = exports.default = PopoverContainer;
|
|
@@ -60,6 +60,10 @@ const PopoverContainerContentStyle = exports.PopoverContainerContentStyle = _sty
|
|
|
60
60
|
}) => theme.zIndex.popover};
|
|
61
61
|
|
|
62
62
|
${animationToRender}
|
|
63
|
+
|
|
64
|
+
:focus {
|
|
65
|
+
outline: none;
|
|
66
|
+
}
|
|
63
67
|
`;
|
|
64
68
|
const PopoverContainerOpenIcon = exports.PopoverContainerOpenIcon = (0, _styledComponents.default)(_iconButton.default)`
|
|
65
69
|
${_icon.default} {
|