@primer/components 0.0.0-202111619107 → 0.0.0-2021116202529
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/dist/browser.esm.js +2 -2
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +2 -2
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.js +3 -3
- package/lib/ActionList/List.js +2 -2
- package/lib/ActionList2/Item.js +6 -4
- package/lib/ActionList2/List.js +2 -2
- package/lib/ActionList2/{ActionListContainerContext.d.ts → MenuContext.d.ts} +3 -3
- package/lib/ActionList2/{ActionListContainerContext.js → MenuContext.js} +3 -3
- package/lib/ActionList2/Selection.js +4 -4
- package/lib/ActionMenu2.d.ts +9 -13
- package/lib/ActionMenu2.js +29 -63
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +1 -1
- package/lib/Autocomplete/AutocompleteMenu.js +5 -10
- package/lib/Checkbox.d.ts +1 -1
- package/lib/Dialog/ConfirmationDialog.js +2 -2
- package/lib/Dialog/Dialog.js +2 -2
- package/lib/FilteredActionList/FilteredActionList.js +3 -10
- package/lib/Overlay.d.ts +1 -1
- package/lib/TextInputWithTokens.js +4 -4
- package/lib/behaviors/anchoredPosition.d.ts +89 -0
- package/lib/behaviors/anchoredPosition.js +316 -0
- package/lib/behaviors/focusTrap.d.ts +12 -0
- package/lib/behaviors/focusTrap.js +179 -0
- package/lib/behaviors/focusZone.d.ts +137 -0
- package/lib/behaviors/focusZone.js +578 -0
- package/lib/behaviors/scrollIntoViewingArea.d.ts +1 -0
- package/lib/behaviors/scrollIntoViewingArea.js +39 -0
- package/lib/hooks/index.d.ts +0 -1
- package/lib/hooks/index.js +1 -9
- package/lib/hooks/useAnchoredPosition.d.ts +1 -1
- package/lib/hooks/useAnchoredPosition.js +2 -2
- package/lib/hooks/useFocusTrap.js +2 -2
- package/lib/hooks/useFocusZone.d.ts +1 -1
- package/lib/hooks/useFocusZone.js +2 -2
- package/lib/hooks/useOpenAndCloseFocus.js +2 -2
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -8
- package/lib/utils/iterateFocusableElements.d.ts +42 -0
- package/lib/utils/iterateFocusableElements.js +113 -0
- package/lib/utils/uniqueId.d.ts +1 -0
- package/lib/utils/uniqueId.js +12 -0
- package/lib/utils/userAgent.d.ts +1 -0
- package/lib/utils/userAgent.js +15 -0
- package/lib-esm/ActionList/Item.js +1 -1
- package/lib-esm/ActionList/List.js +1 -1
- package/lib-esm/ActionList2/Item.js +6 -4
- package/lib-esm/ActionList2/List.js +2 -2
- package/lib-esm/ActionList2/{ActionListContainerContext.d.ts → MenuContext.d.ts} +3 -3
- package/lib-esm/ActionList2/{ActionListContainerContext.js → MenuContext.js} +1 -1
- package/lib-esm/ActionList2/Selection.js +4 -4
- package/lib-esm/ActionMenu2.d.ts +9 -13
- package/lib-esm/ActionMenu2.js +27 -60
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -1
- package/lib-esm/Autocomplete/AutocompleteMenu.js +4 -9
- package/lib-esm/Checkbox.d.ts +1 -1
- package/lib-esm/Dialog/ConfirmationDialog.js +1 -1
- package/lib-esm/Dialog/Dialog.js +1 -1
- package/lib-esm/FilteredActionList/FilteredActionList.js +3 -9
- package/lib-esm/Overlay.d.ts +1 -1
- package/lib-esm/TextInputWithTokens.js +2 -2
- package/lib-esm/behaviors/anchoredPosition.d.ts +89 -0
- package/lib-esm/behaviors/anchoredPosition.js +309 -0
- package/lib-esm/behaviors/focusTrap.d.ts +12 -0
- package/lib-esm/behaviors/focusTrap.js +170 -0
- package/lib-esm/behaviors/focusZone.d.ts +137 -0
- package/lib-esm/behaviors/focusZone.js +560 -0
- package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +1 -0
- package/lib-esm/behaviors/scrollIntoViewingArea.js +30 -0
- package/lib-esm/hooks/index.d.ts +0 -1
- package/lib-esm/hooks/index.js +1 -2
- package/lib-esm/hooks/useAnchoredPosition.d.ts +1 -1
- package/lib-esm/hooks/useAnchoredPosition.js +1 -1
- package/lib-esm/hooks/useFocusTrap.js +1 -1
- package/lib-esm/hooks/useFocusZone.d.ts +1 -1
- package/lib-esm/hooks/useFocusZone.js +1 -1
- package/lib-esm/hooks/useOpenAndCloseFocus.js +1 -1
- package/lib-esm/index.d.ts +0 -2
- package/lib-esm/index.js +0 -1
- package/lib-esm/utils/iterateFocusableElements.d.ts +42 -0
- package/lib-esm/utils/iterateFocusableElements.js +102 -0
- package/lib-esm/utils/uniqueId.d.ts +1 -0
- package/lib-esm/utils/uniqueId.js +5 -0
- package/lib-esm/utils/userAgent.d.ts +1 -0
- package/lib-esm/utils/userAgent.js +8 -0
- package/package.json +5 -2
- package/lib/Radio.d.ts +0 -38
- package/lib/Radio.js +0 -55
- package/lib-esm/Radio.d.ts +0 -38
- package/lib-esm/Radio.js +0 -40
package/lib/ActionList/Item.js
CHANGED
@@ -23,7 +23,7 @@ var _Divider = require("./Divider");
|
|
23
23
|
|
24
24
|
var _ThemeProvider = require("../ThemeProvider");
|
25
25
|
|
26
|
-
var
|
26
|
+
var _focusZone = require("../behaviors/focusZone");
|
27
27
|
|
28
28
|
var _ssr = require("@react-aria/ssr");
|
29
29
|
|
@@ -98,10 +98,10 @@ const StyledItem = _styledComponents.default.div.withConfig({
|
|
98
98
|
showDivider
|
99
99
|
}) => showDivider ? `1px` : '0', DividedContent, (0, _constants.get)('colors.border.muted'), ({
|
100
100
|
showDivider
|
101
|
-
}) => showDivider ? `1px` : '0', DividedContent, DividedContent, DividedContent, DividedContent,
|
101
|
+
}) => showDivider ? `1px` : '0', DividedContent, DividedContent, DividedContent, DividedContent, _focusZone.isActiveDescendantAttribute, DividedContent, _focusZone.isActiveDescendantAttribute, DividedContent, _focusZone.isActiveDescendantAttribute, _focusZone.activeDescendantActivatedDirectly, ({
|
102
102
|
variant,
|
103
103
|
item
|
104
|
-
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).focusBg,
|
104
|
+
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).focusBg, _focusZone.isActiveDescendantAttribute, _focusZone.activeDescendantActivatedIndirectly, ({
|
105
105
|
variant,
|
106
106
|
item
|
107
107
|
}) => getItemVariant(variant, item === null || item === void 0 ? void 0 : item.disabled).hoverBg, ({
|
package/lib/ActionList/List.js
CHANGED
@@ -17,7 +17,7 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
17
17
|
|
18
18
|
var _constants = require("../constants");
|
19
19
|
|
20
|
-
var
|
20
|
+
var _focusZone = require("../behaviors/focusZone");
|
21
21
|
|
22
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
23
|
|
@@ -38,7 +38,7 @@ function isGroupedListProps(props) {
|
|
38
38
|
const StyledList = _styledComponents.default.div.withConfig({
|
39
39
|
displayName: "List__StyledList",
|
40
40
|
componentId: "sc-yr2k7d-0"
|
41
|
-
})(["font-size:", ";line-height:20px;&[", "],&:focus-within{--item-hover-bg-override:none;--item-hover-divider-border-color-override:", ";}"], (0, _constants.get)('fontSizes.1'),
|
41
|
+
})(["font-size:", ";line-height:20px;&[", "],&:focus-within{--item-hover-bg-override:none;--item-hover-divider-border-color-override:", ";}"], (0, _constants.get)('fontSizes.1'), _focusZone.hasActiveDescendantAttribute, (0, _constants.get)('colors.border.muted'));
|
42
42
|
/**
|
43
43
|
* Returns `sx` prop values for `List` children matching the given `List` style variation.
|
44
44
|
* @param variant `List` style variation.
|
package/lib/ActionList2/Item.js
CHANGED
@@ -21,7 +21,7 @@ var _createSlots = _interopRequireDefault(require("../utils/create-slots"));
|
|
21
21
|
|
22
22
|
var _List = require("./List");
|
23
23
|
|
24
|
-
var
|
24
|
+
var _MenuContext = require("./MenuContext");
|
25
25
|
|
26
26
|
var _Selection = require("./Selection");
|
27
27
|
|
@@ -96,7 +96,7 @@ const Item = /*#__PURE__*/_react.default.forwardRef(({
|
|
96
96
|
const {
|
97
97
|
itemRole,
|
98
98
|
afterSelect
|
99
|
-
} = _react.default.useContext(
|
99
|
+
} = _react.default.useContext(_MenuContext.MenuContext);
|
100
100
|
|
101
101
|
const {
|
102
102
|
theme
|
@@ -171,20 +171,22 @@ const Item = /*#__PURE__*/_react.default.forwardRef(({
|
|
171
171
|
};
|
172
172
|
|
173
173
|
const clickHandler = _react.default.useCallback(event => {
|
174
|
+
if (typeof onSelect !== 'function') return;
|
174
175
|
if (disabled) return;
|
175
176
|
|
176
177
|
if (!event.defaultPrevented) {
|
177
|
-
|
178
|
+
onSelect(event); // if this Item is inside a Menu, close the Menu
|
178
179
|
|
179
180
|
if (typeof afterSelect === 'function') afterSelect();
|
180
181
|
}
|
181
182
|
}, [onSelect, disabled, afterSelect]);
|
182
183
|
|
183
184
|
const keyPressHandler = _react.default.useCallback(event => {
|
185
|
+
if (typeof onSelect !== 'function') return;
|
184
186
|
if (disabled) return;
|
185
187
|
|
186
188
|
if (!event.defaultPrevented && [' ', 'Enter'].includes(event.key)) {
|
187
|
-
|
189
|
+
onSelect(event); // if this Item is inside a Menu, close the Menu
|
188
190
|
|
189
191
|
if (typeof afterSelect === 'function') afterSelect();
|
190
192
|
}
|
package/lib/ActionList2/List.js
CHANGED
@@ -11,7 +11,7 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
11
|
|
12
12
|
var _sx = _interopRequireWildcard(require("../sx"));
|
13
13
|
|
14
|
-
var
|
14
|
+
var _MenuContext = require("./MenuContext");
|
15
15
|
|
16
16
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
17
17
|
|
@@ -48,7 +48,7 @@ const List = /*#__PURE__*/_react.default.forwardRef(({
|
|
48
48
|
|
49
49
|
const {
|
50
50
|
listRole
|
51
|
-
} = _react.default.useContext(
|
51
|
+
} = _react.default.useContext(_MenuContext.MenuContext);
|
52
52
|
|
53
53
|
return /*#__PURE__*/_react.default.createElement(ListBox, _extends({
|
54
54
|
sx: (0, _sx.merge)(styles, sxProp),
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/** This context can be used by components that compose ActionList inside a Menu */
|
2
2
|
import React from 'react';
|
3
3
|
declare type ContextProps = {
|
4
|
-
|
4
|
+
parent?: string;
|
5
5
|
listRole?: string;
|
6
6
|
itemRole?: string;
|
7
|
-
afterSelect?:
|
7
|
+
afterSelect?: () => void;
|
8
8
|
};
|
9
|
-
export declare const
|
9
|
+
export declare const MenuContext: React.Context<ContextProps>;
|
10
10
|
export {};
|
@@ -3,13 +3,13 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.MenuContext = void 0;
|
7
7
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
9
9
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
11
|
|
12
12
|
/** This context can be used by components that compose ActionList inside a Menu */
|
13
|
-
const
|
13
|
+
const MenuContext = /*#__PURE__*/_react.default.createContext({});
|
14
14
|
|
15
|
-
exports.
|
15
|
+
exports.MenuContext = MenuContext;
|
@@ -13,7 +13,7 @@ var _List = require("./List");
|
|
13
13
|
|
14
14
|
var _Group = require("./Group");
|
15
15
|
|
16
|
-
var
|
16
|
+
var _MenuContext = require("./MenuContext");
|
17
17
|
|
18
18
|
var _Visuals = require("./Visuals");
|
19
19
|
|
@@ -31,8 +31,8 @@ const Selection = ({
|
|
31
31
|
} = _react.default.useContext(_Group.GroupContext);
|
32
32
|
|
33
33
|
const {
|
34
|
-
|
35
|
-
} = _react.default.useContext(
|
34
|
+
parent
|
35
|
+
} = _react.default.useContext(_MenuContext.MenuContext);
|
36
36
|
/** selectionVariant in Group can override the selectionVariant in List root */
|
37
37
|
|
38
38
|
|
@@ -44,7 +44,7 @@ const Selection = ({
|
|
44
44
|
return null;
|
45
45
|
}
|
46
46
|
|
47
|
-
if (
|
47
|
+
if (parent === 'ActionMenu') {
|
48
48
|
throw new Error('ActionList cannot have a selectionVariant inside ActionMenu, please use DropdownMenu or SelectPanel instead. More information: https://primer.style/design/components/action-list#application');
|
49
49
|
return null;
|
50
50
|
}
|
package/lib/ActionMenu2.d.ts
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
import { ButtonProps } from './Button';
|
2
2
|
import React from 'react';
|
3
|
-
import { AnchoredOverlayProps } from './AnchoredOverlay';
|
4
3
|
import { OverlayProps } from './Overlay';
|
5
|
-
|
6
|
-
|
7
|
-
export declare type ActionMenuProps = {
|
4
|
+
import { AnchoredOverlayWrapperAnchorProps } from './AnchoredOverlay/AnchoredOverlay';
|
5
|
+
declare type ActionMenuBaseProps = {
|
8
6
|
/**
|
9
|
-
* Recommended: `ActionMenu.Button` or `ActionMenu.Anchor` with `
|
7
|
+
* Recommended: `ActionMenu.Button` or `ActionMenu.Anchor` with ActionList`
|
10
8
|
*/
|
11
9
|
children: React.ReactElement[] | React.ReactElement;
|
12
10
|
/**
|
@@ -17,18 +15,17 @@ export declare type ActionMenuProps = {
|
|
17
15
|
* If defined, will control the open/closed state of the overlay. Must be used in conjuction with `open`.
|
18
16
|
*/
|
19
17
|
onOpenChange?: (s: boolean) => void;
|
20
|
-
|
18
|
+
/**
|
19
|
+
* Props to be spread on the internal `Overlay` component.
|
20
|
+
*/
|
21
|
+
overlayProps?: Partial<OverlayProps>;
|
22
|
+
};
|
23
|
+
export declare type ActionMenuProps = ActionMenuBaseProps & AnchoredOverlayWrapperAnchorProps;
|
21
24
|
export declare type MenuAnchorProps = {
|
22
25
|
children: React.ReactElement;
|
23
26
|
};
|
24
27
|
/** this component is syntactical sugar 🍭 */
|
25
28
|
export declare type MenuButtonProps = ButtonProps;
|
26
|
-
declare type MenuOverlayProps = Partial<OverlayProps> & {
|
27
|
-
/**
|
28
|
-
* Recommended: `ActionList`
|
29
|
-
*/
|
30
|
-
children: React.ReactElement[] | React.ReactElement;
|
31
|
-
};
|
32
29
|
export declare const ActionMenu: React.FC<ActionMenuProps> & {
|
33
30
|
Button: React.ForwardRefExoticComponent<Pick<{
|
34
31
|
color?: string | undefined;
|
@@ -311,7 +308,6 @@ export declare const ActionMenu: React.FC<ActionMenuProps> & {
|
|
311
308
|
variant?: "small" | "medium" | "large" | undefined;
|
312
309
|
}> & React.RefAttributes<React.RefObject<HTMLElement> | undefined>>;
|
313
310
|
Anchor: React.ForwardRefExoticComponent<MenuAnchorProps & React.RefAttributes<React.RefObject<HTMLElement> | undefined>>;
|
314
|
-
Overlay: React.FC<MenuOverlayProps>;
|
315
311
|
Divider: React.FC<import("./sx").SxProp>;
|
316
312
|
};
|
317
313
|
export {};
|
package/lib/ActionMenu2.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.ActionMenu =
|
6
|
+
exports.ActionMenu = void 0;
|
7
7
|
|
8
8
|
var _Button = _interopRequireDefault(require("./Button"));
|
9
9
|
|
@@ -11,60 +11,59 @@ var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
|
12
12
|
var _AnchoredOverlay = require("./AnchoredOverlay");
|
13
13
|
|
14
|
+
var _useProvidedStateOrCreate = require("./hooks/useProvidedStateOrCreate");
|
15
|
+
|
14
16
|
var _hooks = require("./hooks");
|
15
17
|
|
16
18
|
var _Divider = require("./ActionList2/Divider");
|
17
19
|
|
18
|
-
var
|
20
|
+
var _MenuContext = require("./ActionList2/MenuContext");
|
19
21
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
23
|
|
22
|
-
const
|
23
|
-
renderAnchor: null,
|
24
|
-
open: false
|
25
|
-
});
|
26
|
-
|
27
|
-
exports.MenuContext = MenuContext;
|
28
|
-
|
29
|
-
const Menu = ({
|
24
|
+
const ActionMenuBase = ({
|
30
25
|
anchorRef: externalAnchorRef,
|
31
26
|
open,
|
32
27
|
onOpenChange,
|
28
|
+
overlayProps,
|
33
29
|
children
|
34
30
|
}) => {
|
35
|
-
const [combinedOpenState, setCombinedOpenState] = (0,
|
31
|
+
const [combinedOpenState, setCombinedOpenState] = (0, _useProvidedStateOrCreate.useProvidedStateOrCreate)(open, onOpenChange, false);
|
32
|
+
const anchorRef = (0, _hooks.useProvidedRefOrCreate)(externalAnchorRef);
|
36
33
|
|
37
34
|
const onOpen = _react.default.useCallback(() => setCombinedOpenState(true), [setCombinedOpenState]);
|
38
35
|
|
39
36
|
const onClose = _react.default.useCallback(() => setCombinedOpenState(false), [setCombinedOpenState]);
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
// we strip out Anchor from children and pass it to AnchoredOverlay to render
|
44
|
-
// with additional props for accessibility
|
38
|
+
let renderAnchor = null;
|
39
|
+
const contents = [];
|
45
40
|
|
46
|
-
|
41
|
+
_react.default.Children.map(children, child => {
|
47
42
|
if (child.type === MenuButton || child.type === Anchor) {
|
48
43
|
renderAnchor = anchorProps => /*#__PURE__*/_react.default.cloneElement(child, anchorProps);
|
49
|
-
|
50
|
-
|
44
|
+
} else {
|
45
|
+
contents.push(child);
|
51
46
|
}
|
52
|
-
|
53
|
-
return child;
|
54
47
|
});
|
55
48
|
|
56
|
-
return /*#__PURE__*/_react.default.createElement(
|
49
|
+
return /*#__PURE__*/_react.default.createElement(_AnchoredOverlay.AnchoredOverlay, {
|
50
|
+
renderAnchor: renderAnchor,
|
51
|
+
anchorRef: anchorRef,
|
52
|
+
open: combinedOpenState,
|
53
|
+
onOpen: onOpen,
|
54
|
+
onClose: onClose,
|
55
|
+
overlayProps: overlayProps
|
56
|
+
}, /*#__PURE__*/_react.default.createElement(_MenuContext.MenuContext.Provider, {
|
57
57
|
value: {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
onClose
|
58
|
+
parent: 'ActionMenu',
|
59
|
+
listRole: 'menu',
|
60
|
+
itemRole: 'menuitem',
|
61
|
+
afterSelect: onClose
|
63
62
|
}
|
64
|
-
}, contents);
|
63
|
+
}, contents));
|
65
64
|
};
|
66
65
|
|
67
|
-
|
66
|
+
ActionMenuBase.displayName = "ActionMenuBase";
|
68
67
|
|
69
68
|
const Anchor = /*#__PURE__*/_react.default.forwardRef(({
|
70
69
|
children,
|
@@ -83,43 +82,10 @@ const MenuButton = /*#__PURE__*/_react.default.forwardRef((props, anchorRef) =>
|
|
83
82
|
}, /*#__PURE__*/_react.default.createElement(_Button.default, props));
|
84
83
|
});
|
85
84
|
|
86
|
-
|
87
|
-
|
88
|
-
...overlayProps
|
89
|
-
}) => {
|
90
|
-
// we typecast anchorRef as required instead of optional
|
91
|
-
// because we know that we're setting it in context in Menu
|
92
|
-
const {
|
93
|
-
anchorRef,
|
94
|
-
renderAnchor,
|
95
|
-
open,
|
96
|
-
onOpen,
|
97
|
-
onClose
|
98
|
-
} = _react.default.useContext(MenuContext);
|
99
|
-
|
100
|
-
return /*#__PURE__*/_react.default.createElement(_AnchoredOverlay.AnchoredOverlay, {
|
101
|
-
anchorRef: anchorRef,
|
102
|
-
renderAnchor: renderAnchor,
|
103
|
-
open: open,
|
104
|
-
onOpen: onOpen,
|
105
|
-
onClose: onClose,
|
106
|
-
overlayProps: overlayProps
|
107
|
-
}, /*#__PURE__*/_react.default.createElement(_ActionListContainerContext.ActionListContainerContext.Provider, {
|
108
|
-
value: {
|
109
|
-
container: 'ActionMenu',
|
110
|
-
listRole: 'menu',
|
111
|
-
itemRole: 'menuitem',
|
112
|
-
afterSelect: onClose
|
113
|
-
}
|
114
|
-
}, children));
|
115
|
-
};
|
116
|
-
|
117
|
-
Overlay.displayName = "Overlay";
|
118
|
-
Menu.displayName = 'ActionMenu';
|
119
|
-
const ActionMenu = Object.assign(Menu, {
|
85
|
+
ActionMenuBase.displayName = 'ActionMenu';
|
86
|
+
const ActionMenu = Object.assign(ActionMenuBase, {
|
120
87
|
Button: MenuButton,
|
121
88
|
Anchor,
|
122
|
-
Overlay,
|
123
89
|
Divider: _Divider.Divider
|
124
90
|
});
|
125
91
|
exports.ActionMenu = ActionMenu;
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
2
2
|
import { OverlayProps } from '../Overlay';
|
3
3
|
import { FocusTrapHookSettings } from '../hooks/useFocusTrap';
|
4
4
|
import { FocusZoneHookSettings } from '../hooks/useFocusZone';
|
5
|
-
import
|
5
|
+
import { PositionSettings } from '../behaviors/anchoredPosition';
|
6
6
|
interface AnchoredOverlayPropsWithAnchor {
|
7
7
|
/**
|
8
8
|
* A custom function component used to render the anchor element.
|
@@ -17,9 +17,9 @@ var _AutocompleteContext = require("./AutocompleteContext");
|
|
17
17
|
|
18
18
|
var _octiconsReact = require("@primer/octicons-react");
|
19
19
|
|
20
|
-
var
|
20
|
+
var _uniqueId = require("../utils/uniqueId");
|
21
21
|
|
22
|
-
var
|
22
|
+
var _scrollIntoViewingArea = require("../behaviors/scrollIntoViewingArea");
|
23
23
|
|
24
24
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
25
25
|
|
@@ -27,11 +27,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
27
27
|
|
28
28
|
const getDefaultSortFn = isItemSelectedFn => (itemIdA, itemIdB) => isItemSelectedFn(itemIdA) === isItemSelectedFn(itemIdB) ? 0 : isItemSelectedFn(itemIdA) ? -1 : 1;
|
29
29
|
|
30
|
-
const menuScrollMargins = {
|
31
|
-
startMargin: 0,
|
32
|
-
endMargin: 8
|
33
|
-
};
|
34
|
-
|
35
30
|
function getDefaultItemFilter(filterValue) {
|
36
31
|
return function (item, _i) {
|
37
32
|
var _item$text;
|
@@ -130,7 +125,7 @@ function AutocompleteMenu(props) {
|
|
130
125
|
onAction: item => {
|
131
126
|
// TODO: make it possible to pass a leadingVisual when using `addNewItem`
|
132
127
|
addNewItem.handleAddItem({ ...item,
|
133
|
-
id: item.id || (0,
|
128
|
+
id: item.id || (0, _uniqueId.uniqueId)(),
|
134
129
|
leadingVisual: undefined
|
135
130
|
});
|
136
131
|
|
@@ -157,9 +152,9 @@ function AutocompleteMenu(props) {
|
|
157
152
|
}
|
158
153
|
|
159
154
|
if (current && customScrollContainerRef && customScrollContainerRef.current && directlyActivated) {
|
160
|
-
(0,
|
155
|
+
(0, _scrollIntoViewingArea.scrollIntoViewingArea)(current, customScrollContainerRef.current);
|
161
156
|
} else if (current && scrollContainerRef.current && directlyActivated) {
|
162
|
-
(0,
|
157
|
+
(0, _scrollIntoViewingArea.scrollIntoViewingArea)(current, scrollContainerRef.current);
|
163
158
|
}
|
164
159
|
}
|
165
160
|
}, [loading]);
|
package/lib/Checkbox.d.ts
CHANGED
@@ -25,5 +25,5 @@ export declare type CheckboxProps = {
|
|
25
25
|
/**
|
26
26
|
* An accessible, native checkbox component
|
27
27
|
*/
|
28
|
-
declare const Checkbox: React.ForwardRefExoticComponent<Pick<CheckboxProps, "sx" | keyof React.InputHTMLAttributes<HTMLInputElement> | "
|
28
|
+
declare const Checkbox: React.ForwardRefExoticComponent<Pick<CheckboxProps, "sx" | keyof React.InputHTMLAttributes<HTMLInputElement> | "indeterminate" | "validationStatus"> & React.RefAttributes<HTMLInputElement>>;
|
29
29
|
export default Checkbox;
|
@@ -16,7 +16,7 @@ var _Box = _interopRequireDefault(require("../Box"));
|
|
16
16
|
|
17
17
|
var _ThemeProvider = require("../ThemeProvider");
|
18
18
|
|
19
|
-
var
|
19
|
+
var _focusZone = require("../behaviors/focusZone");
|
20
20
|
|
21
21
|
var _constants = require("../constants");
|
22
22
|
|
@@ -81,7 +81,7 @@ const ConfirmationFooter = ({
|
|
81
81
|
const {
|
82
82
|
containerRef: footerRef
|
83
83
|
} = (0, _useFocusZone.useFocusZone)({
|
84
|
-
bindKeys:
|
84
|
+
bindKeys: _focusZone.FocusKeys.ArrowHorizontal | _focusZone.FocusKeys.Tab,
|
85
85
|
focusInStrategy: 'closest'
|
86
86
|
}); // Must have exactly 2 buttons!
|
87
87
|
|
package/lib/Dialog/Dialog.js
CHANGED
@@ -27,7 +27,7 @@ var _octiconsReact = require("@primer/octicons-react");
|
|
27
27
|
|
28
28
|
var _useFocusZone = require("../hooks/useFocusZone");
|
29
29
|
|
30
|
-
var
|
30
|
+
var _focusZone = require("../behaviors/focusZone");
|
31
31
|
|
32
32
|
var _Portal = _interopRequireDefault(require("../Portal"));
|
33
33
|
|
@@ -121,7 +121,7 @@ const DefaultFooter = ({
|
|
121
121
|
const {
|
122
122
|
containerRef: footerRef
|
123
123
|
} = (0, _useFocusZone.useFocusZone)({
|
124
|
-
bindKeys:
|
124
|
+
bindKeys: _focusZone.FocusKeys.ArrowHorizontal | _focusZone.FocusKeys.Tab,
|
125
125
|
focusInStrategy: 'closest'
|
126
126
|
});
|
127
127
|
return footerButtons ? /*#__PURE__*/_react.default.createElement(Dialog.Footer, {
|
@@ -29,7 +29,7 @@ var _useProvidedRefOrCreate = require("../hooks/useProvidedRefOrCreate");
|
|
29
29
|
|
30
30
|
var _useScrollFlash = _interopRequireDefault(require("../hooks/useScrollFlash"));
|
31
31
|
|
32
|
-
var
|
32
|
+
var _scrollIntoViewingArea = require("../behaviors/scrollIntoViewingArea");
|
33
33
|
|
34
34
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
35
35
|
|
@@ -39,11 +39,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
39
39
|
|
40
40
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
41
41
|
|
42
|
-
const menuScrollMargins = {
|
43
|
-
startMargin: 0,
|
44
|
-
endMargin: 8
|
45
|
-
};
|
46
|
-
|
47
42
|
const StyledHeader = _styledComponents.default.div.withConfig({
|
48
43
|
displayName: "FilteredActionList__StyledHeader",
|
49
44
|
componentId: "sc-yg3jkv-0"
|
@@ -91,7 +86,7 @@ function FilteredActionList({
|
|
91
86
|
activeDescendantRef.current = current;
|
92
87
|
|
93
88
|
if (current && scrollContainerRef.current && directlyActivated) {
|
94
|
-
(0,
|
89
|
+
(0, _scrollIntoViewingArea.scrollIntoViewingArea)(current, scrollContainerRef.current);
|
95
90
|
}
|
96
91
|
}
|
97
92
|
}, [// List ref isn't set while loading. Need to re-bind focus zone when it changes
|
@@ -99,9 +94,7 @@ function FilteredActionList({
|
|
99
94
|
(0, _react.useEffect)(() => {
|
100
95
|
// if items changed, we want to instantly move active descendant into view
|
101
96
|
if (activeDescendantRef.current && scrollContainerRef.current) {
|
102
|
-
(0,
|
103
|
-
behavior: 'auto'
|
104
|
-
});
|
97
|
+
(0, _scrollIntoViewingArea.scrollIntoViewingArea)(activeDescendantRef.current, scrollContainerRef.current, 'vertical', undefined, undefined, 'auto');
|
105
98
|
}
|
106
99
|
}, [items]);
|
107
100
|
(0, _useScrollFlash.default)(scrollContainerRef);
|
package/lib/Overlay.d.ts
CHANGED
@@ -2,7 +2,7 @@ import React, { ComponentPropsWithRef } from 'react';
|
|
2
2
|
import { AriaRole, Merge } from './utils/types';
|
3
3
|
import { TouchOrMouseEvent } from './hooks';
|
4
4
|
import { SxProp } from './sx';
|
5
|
-
import
|
5
|
+
import { AnchorSide } from './behaviors/anchoredPosition';
|
6
6
|
import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
|
7
7
|
declare type StyledOverlayProps = {
|
8
8
|
width?: keyof typeof widthMap;
|
@@ -9,7 +9,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
10
10
|
var _props = require("@styled-system/props");
|
11
11
|
|
12
|
-
var
|
12
|
+
var _focusZone = require("./behaviors/focusZone");
|
13
13
|
|
14
14
|
var _useCombinedRefs = require("./hooks/useCombinedRefs");
|
15
15
|
|
@@ -27,7 +27,7 @@ var _Box = _interopRequireDefault(require("./Box"));
|
|
27
27
|
|
28
28
|
var _Text = _interopRequireDefault(require("./Text"));
|
29
29
|
|
30
|
-
var
|
30
|
+
var _iterateFocusableElements = require("./utils/iterateFocusableElements");
|
31
31
|
|
32
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33
33
|
|
@@ -81,7 +81,7 @@ function TextInputWithTokensInnerComponent({
|
|
81
81
|
containerRef
|
82
82
|
} = (0, _useFocusZone.useFocusZone)({
|
83
83
|
focusOutBehavior: 'wrap',
|
84
|
-
bindKeys:
|
84
|
+
bindKeys: _focusZone.FocusKeys.ArrowHorizontal | _focusZone.FocusKeys.HomeAndEnd,
|
85
85
|
focusableElementFilter: element => {
|
86
86
|
return !element.getAttributeNames().includes('aria-hidden');
|
87
87
|
},
|
@@ -119,7 +119,7 @@ function TextInputWithTokensInnerComponent({
|
|
119
119
|
const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex || 0]; // when removing the first token by keying "Backspace" or "Delete",
|
120
120
|
// `nextFocusableElement` is the div that wraps the input
|
121
121
|
|
122
|
-
const firstFocusable = nextElementToFocus && (0,
|
122
|
+
const firstFocusable = nextElementToFocus && (0, _iterateFocusableElements.isFocusable)(nextElementToFocus) ? nextElementToFocus : Array.from(((_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.children) || []).find(el => (0, _iterateFocusableElements.isFocusable)(el));
|
123
123
|
|
124
124
|
if (firstFocusable) {
|
125
125
|
firstFocusable.focus();
|
@@ -0,0 +1,89 @@
|
|
1
|
+
export declare type AnchorAlignment = 'start' | 'center' | 'end';
|
2
|
+
export declare type AnchorSide = 'inside-top' | 'inside-bottom' | 'inside-left' | 'inside-right' | 'inside-center' | 'outside-top' | 'outside-bottom' | 'outside-left' | 'outside-right';
|
3
|
+
/**
|
4
|
+
* Settings that customize how a floating element is positioned
|
5
|
+
* with respect to an anchor element.
|
6
|
+
*/
|
7
|
+
export interface PositionSettings {
|
8
|
+
/**
|
9
|
+
* Sets the side of the anchor element that the floating element should be
|
10
|
+
* pinned to. This side is given by a string starting with either "inside" or
|
11
|
+
* "outside", followed by a hyphen, followed by either "top", "right", "bottom",
|
12
|
+
* or "left". Additionally, "inside-center" is an allowed value.
|
13
|
+
*
|
14
|
+
* The first part of this string, "inside" or "outside", determines whether the
|
15
|
+
* floating element should be attempted to be placed "inside" the anchor element
|
16
|
+
* or "outside" of it. Using "inside" is useful for making it appear that the
|
17
|
+
* anchor _contains_ the floating element, and it can be used for implementing a
|
18
|
+
* dialog that is centered on the screen. The "outside" value is more common and
|
19
|
+
* can be used for tooltips, popovers, menus, etc.
|
20
|
+
*
|
21
|
+
* The second part of this string determines the _edge_ on the anchor element that
|
22
|
+
* the floating element will be anchored to. If side is "inside-center", then
|
23
|
+
* the floating element will be centered in the X-direction (while align is used
|
24
|
+
* to position it in the Y-direction).
|
25
|
+
* Note: "outside-center" is _not_ a valid value for this property.
|
26
|
+
*/
|
27
|
+
side: AnchorSide;
|
28
|
+
/**
|
29
|
+
* Determines how the floating element should align with the anchor element. If
|
30
|
+
* set to "start", the floating element's first edge (top or left) will align
|
31
|
+
* with the anchor element's first edge. If set to "center", the floating
|
32
|
+
* element will be centered along the axis of the anchor edge. If set to "end",
|
33
|
+
* the floating element's last edge will align with the anchor element's last edge.
|
34
|
+
*/
|
35
|
+
align: AnchorAlignment;
|
36
|
+
/**
|
37
|
+
* The number of pixels between the anchor edge and the floating element.
|
38
|
+
*
|
39
|
+
* Positive values move the floating element farther from the anchor element
|
40
|
+
* (for outside positioning) or further inside the anchor element (for inside
|
41
|
+
* positioning). Negative values have the opposite effect.
|
42
|
+
*/
|
43
|
+
anchorOffset: number;
|
44
|
+
/**
|
45
|
+
* An additional offset, in pixels, to move the floating element from
|
46
|
+
* the aligning edge.
|
47
|
+
*
|
48
|
+
* Positive values move the floating element in the direction of center-
|
49
|
+
* alignment. Negative values move the floating element away from center-
|
50
|
+
* alignment. When align is "center", positive offsets move the floating
|
51
|
+
* element right (top or bottom anchor side) or down (left or right
|
52
|
+
* anchor side).
|
53
|
+
*/
|
54
|
+
alignmentOffset: number;
|
55
|
+
/**
|
56
|
+
* If false, when the above settings result in rendering the floating element
|
57
|
+
* wholly or partially outside of the bounds of the containing element, attempt
|
58
|
+
* to adjust the settings to prevent this. Only applies to "outside" positioning.
|
59
|
+
*
|
60
|
+
* First, attempt to flip to the opposite edge of the anchor if the floating
|
61
|
+
* element is getting clipped in that direction. If flipping results in a
|
62
|
+
* similar clipping, try moving to the adjacent sides.
|
63
|
+
*
|
64
|
+
* Once we find a side that does not clip the overlay in its own dimension,
|
65
|
+
* check the rest of the sides to see if we need to adjust the alignment offset
|
66
|
+
* to fit in other dimensions.
|
67
|
+
*
|
68
|
+
* If we try all four sides and get clipped each time, settle for overflowing
|
69
|
+
* and use the "bottom" side, since the ability to scroll is most likely in
|
70
|
+
* this direction.
|
71
|
+
*/
|
72
|
+
allowOutOfBounds: boolean;
|
73
|
+
}
|
74
|
+
export interface AnchorPosition {
|
75
|
+
top: number;
|
76
|
+
left: number;
|
77
|
+
anchorSide: AnchorSide;
|
78
|
+
}
|
79
|
+
/**
|
80
|
+
* Given a floating element and an anchor element, return coordinates for the top-left
|
81
|
+
* of the floating element in order to absolutely position it such that it appears
|
82
|
+
* near the anchor element.
|
83
|
+
*
|
84
|
+
* @param floatingElement Element intended to be positioned near or within an anchor
|
85
|
+
* @param anchorElement The element to serve as the position anchor
|
86
|
+
* @param settings Settings to determine the rules for positioning the floating element
|
87
|
+
* @returns {top: number, left: number} coordinates for the floating element
|
88
|
+
*/
|
89
|
+
export declare function getAnchoredPosition(floatingElement: Element, anchorElement: Element | DOMRect, settings?: Partial<PositionSettings>): AnchorPosition;
|