@atlaskit/dropdown-menu 11.0.3 → 11.1.2
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/CHANGELOG.md +25 -0
- package/codemods/11.0.0-lite-mode.tsx +12 -0
- package/codemods/__tests__/11.0.0-lite-mode.test.tsx +22 -2
- package/codemods/__tests__/convert-triggerType.test.tsx +89 -6
- package/codemods/migrates/convert-trigger-type.tsx +14 -5
- package/codemods/migrates/deprecate-autoFocus.tsx +18 -0
- package/codemods/migrates/deprecate-boundariesElement.tsx +9 -0
- package/codemods/migrates/deprecate-isCompact.tsx +18 -0
- package/codemods/migrates/deprecate-isHidden.tsx +18 -0
- package/codemods/migrates/deprecate-isMenuFixed.tsx +9 -0
- package/dist/cjs/checkbox/dropdown-item-checkbox.js +2 -1
- package/dist/cjs/dropdown-menu.js +43 -29
- package/dist/cjs/internal/components/menu-wrapper.js +3 -1
- package/dist/cjs/internal/utils/use-generated-id.js +29 -0
- package/dist/cjs/radio/dropdown-item-radio.js +2 -1
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/visual-regression/index.js +93 -0
- package/dist/es2019/checkbox/dropdown-item-checkbox.js +2 -1
- package/dist/es2019/dropdown-menu.js +37 -31
- package/dist/es2019/internal/components/menu-wrapper.js +3 -1
- package/dist/es2019/internal/utils/use-generated-id.js +18 -0
- package/dist/es2019/radio/dropdown-item-radio.js +2 -1
- package/dist/es2019/version.json +1 -1
- package/dist/es2019/visual-regression/index.js +30 -0
- package/dist/esm/checkbox/dropdown-item-checkbox.js +2 -1
- package/dist/esm/dropdown-menu.js +41 -30
- package/dist/esm/internal/components/menu-wrapper.js +3 -1
- package/dist/esm/internal/utils/use-generated-id.js +21 -0
- package/dist/esm/radio/dropdown-item-radio.js +2 -1
- package/dist/esm/version.json +1 -1
- package/dist/esm/visual-regression/index.js +86 -0
- package/dist/types/internal/utils/use-generated-id.d.ts +5 -0
- package/dist/types/types.d.ts +6 -0
- package/dist/types/visual-regression/index.d.ts +1 -0
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @atlaskit/dropdown-menu
|
|
2
2
|
|
|
3
|
+
## 11.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 11.1.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`dbf652b5183`](https://bitbucket.org/atlassian/atlassian-frontend/commits/dbf652b5183) - Fixes an accessibility issue where menu items had the ARIA role of `menuitem` but were not contained by a parent with the correct role. The `MenuWrapper` component now has `role="menu"`.
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
16
|
+
## 11.1.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- [`bb8a0f713e8`](https://bitbucket.org/atlassian/atlassian-frontend/commits/bb8a0f713e8) - Add zIndex prop to pass custom z-index for the menu if it clashes with other components on the screen
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- [`58884c2f6c1`](https://bitbucket.org/atlassian/atlassian-frontend/commits/58884c2f6c1) - Internal code change turning on a new linting rule.
|
|
25
|
+
- [`94886036118`](https://bitbucket.org/atlassian/atlassian-frontend/commits/94886036118) - Internal refactor to properly use render props to avoid unwanted re-mounts and improve test coverage
|
|
26
|
+
- Updated dependencies
|
|
27
|
+
|
|
3
28
|
## 11.0.3
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { createTransformer } from '@atlaskit/codemod-utils';
|
|
2
2
|
|
|
3
3
|
import convertTriggerType from './migrates/convert-trigger-type';
|
|
4
|
+
import deprecateAutoFocus from './migrates/deprecate-autoFocus';
|
|
5
|
+
import deprecateboundariesElement from './migrates/deprecate-boundariesElement';
|
|
6
|
+
import deprecateIsCompact from './migrates/deprecate-isCompact';
|
|
7
|
+
import deprecateIsHidden from './migrates/deprecate-isHidden';
|
|
8
|
+
import deprecateIsMenuFixed from './migrates/deprecate-isMenuFixed';
|
|
4
9
|
import deprecateItems from './migrates/deprecate-items';
|
|
5
10
|
import deprecateOnItemActivated from './migrates/deprecate-onItemActivated';
|
|
6
11
|
import deprecateOnPositioned from './migrates/deprecate-onPositioned';
|
|
@@ -22,6 +27,13 @@ const transformer = createTransformer([
|
|
|
22
27
|
deprecateOnItemActivated,
|
|
23
28
|
deprecateOnPositioned,
|
|
24
29
|
deprecateShouldFitContainer,
|
|
30
|
+
deprecateboundariesElement,
|
|
31
|
+
deprecateIsMenuFixed,
|
|
32
|
+
|
|
33
|
+
// props on *Items
|
|
34
|
+
...deprecateAutoFocus(),
|
|
35
|
+
...deprecateIsCompact(),
|
|
36
|
+
...deprecateIsHidden(),
|
|
25
37
|
|
|
26
38
|
replaceShouldAllowMultiline,
|
|
27
39
|
updatePositionValue,
|
|
@@ -12,7 +12,7 @@ describe('apply all needed codemods for version 11.0.0 major bump', () => {
|
|
|
12
12
|
`
|
|
13
13
|
import React from "react";
|
|
14
14
|
import DropdownMenu, {
|
|
15
|
-
DropdownItemGroupCheckbox as MyComponent, DropdownItemCheckbox,
|
|
15
|
+
DropdownItemGroupCheckbox as MyComponent, DropdownItemCheckbox, DropdownItem, DropdownItemRadio,
|
|
16
16
|
} from "@atlaskit/dropdown-menu";
|
|
17
17
|
|
|
18
18
|
export default () => (
|
|
@@ -24,14 +24,31 @@ describe('apply all needed codemods for version 11.0.0 major bump', () => {
|
|
|
24
24
|
onPositioned={() => {}}
|
|
25
25
|
position="bottom left"
|
|
26
26
|
shouldFitContainer={false}
|
|
27
|
+
boundariesElement={document.body}
|
|
28
|
+
isMenuFixed
|
|
27
29
|
shouldAllowMultiline>
|
|
30
|
+
<DropdownItem
|
|
31
|
+
isHidden
|
|
32
|
+
autoFocus
|
|
33
|
+
isCompact
|
|
34
|
+
>Cut</DropdownItem>
|
|
35
|
+
<DropdownItemCheckbox
|
|
36
|
+
isHidden
|
|
37
|
+
autoFocus
|
|
38
|
+
isCompact
|
|
39
|
+
>Copy</DropdownItemCheckbox>
|
|
40
|
+
<DropdownItemRadio
|
|
41
|
+
isHidden
|
|
42
|
+
autoFocus
|
|
43
|
+
isCompact
|
|
44
|
+
>Paste</DropdownItemRadio>
|
|
28
45
|
</DropdownMenu>
|
|
29
46
|
);
|
|
30
47
|
`,
|
|
31
48
|
`
|
|
32
49
|
import React from "react";
|
|
33
50
|
import DropdownMenu, {
|
|
34
|
-
DropdownItemCheckboxGroup as MyComponent, DropdownItemCheckbox,
|
|
51
|
+
DropdownItemCheckboxGroup as MyComponent, DropdownItemCheckbox, DropdownItem, DropdownItemRadio,
|
|
35
52
|
} from "@atlaskit/dropdown-menu";
|
|
36
53
|
|
|
37
54
|
export default () => (
|
|
@@ -40,6 +57,9 @@ describe('apply all needed codemods for version 11.0.0 major bump', () => {
|
|
|
40
57
|
placement="bottom-start"
|
|
41
58
|
shouldTitleWrap
|
|
42
59
|
shouldDescriptionWrap>
|
|
60
|
+
<DropdownItem>Cut</DropdownItem>
|
|
61
|
+
<DropdownItemCheckbox>Copy</DropdownItemCheckbox>
|
|
62
|
+
<DropdownItemRadio>Paste</DropdownItemRadio>
|
|
43
63
|
</DropdownMenu>
|
|
44
64
|
);
|
|
45
65
|
`,
|
|
@@ -66,7 +66,7 @@ describe('update position value', () => {
|
|
|
66
66
|
import DropdownMenu from "@atlaskit/dropdown-menu";
|
|
67
67
|
|
|
68
68
|
export default () => (
|
|
69
|
-
<DropdownMenu
|
|
69
|
+
<DropdownMenu
|
|
70
70
|
trigger={
|
|
71
71
|
<div>
|
|
72
72
|
<button/> trigger
|
|
@@ -81,20 +81,103 @@ describe('update position value', () => {
|
|
|
81
81
|
import DropdownMenu from "@atlaskit/dropdown-menu";
|
|
82
82
|
|
|
83
83
|
export default () => (
|
|
84
|
-
|
|
84
|
+
<DropdownMenu
|
|
85
|
+
/* TODO: (from codemod)
|
|
85
86
|
The usage of the 'trigger', 'triggerType' and 'triggerButtonProps' prop in this component could not be transformed and requires manual intervention.
|
|
86
|
-
Since version 11.0.0, we simplified the API and
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
Since version 11.0.0, we have simplified the API and now only use the 'trigger' prop.
|
|
88
|
+
Please refer to https://hello.atlassian.net/wiki/spaces/DST/pages/1330997516/Dropdown+menu+upgrade+guide for more details.
|
|
89
|
+
And feel free to reach out to us on our support channel if you have more queries – #help-design-system. */
|
|
89
90
|
trigger={
|
|
90
91
|
<div>
|
|
91
92
|
<button/> trigger
|
|
92
93
|
</div>
|
|
93
94
|
}
|
|
94
95
|
triggerType="button">
|
|
95
|
-
</DropdownMenu>
|
|
96
|
+
</DropdownMenu>
|
|
96
97
|
);
|
|
97
98
|
`,
|
|
98
99
|
'should only add comments triggerType prop when trigger is an object',
|
|
99
100
|
);
|
|
101
|
+
|
|
102
|
+
defineInlineTest(
|
|
103
|
+
{ default: transformer, parser: 'tsx' },
|
|
104
|
+
{},
|
|
105
|
+
`
|
|
106
|
+
import React from "react";
|
|
107
|
+
import DropdownMenu from "@atlaskit/dropdown-menu";
|
|
108
|
+
|
|
109
|
+
export default () => (
|
|
110
|
+
<DropdownMenu
|
|
111
|
+
trigger={
|
|
112
|
+
<div>
|
|
113
|
+
<button/> trigger
|
|
114
|
+
</div>
|
|
115
|
+
}>
|
|
116
|
+
</DropdownMenu>
|
|
117
|
+
);
|
|
118
|
+
`,
|
|
119
|
+
`
|
|
120
|
+
import React from "react";
|
|
121
|
+
import DropdownMenu from "@atlaskit/dropdown-menu";
|
|
122
|
+
|
|
123
|
+
export default () => (
|
|
124
|
+
<DropdownMenu
|
|
125
|
+
/* TODO: (from codemod)
|
|
126
|
+
The usage of the 'trigger', 'triggerType' and 'triggerButtonProps' prop in this component could not be transformed and requires manual intervention.
|
|
127
|
+
Since version 11.0.0, we have simplified the API and now only use the 'trigger' prop.
|
|
128
|
+
Please refer to https://hello.atlassian.net/wiki/spaces/DST/pages/1330997516/Dropdown+menu+upgrade+guide for more details.
|
|
129
|
+
And feel free to reach out to us on our support channel if you have more queries – #help-design-system. */
|
|
130
|
+
trigger={
|
|
131
|
+
<div>
|
|
132
|
+
<button/> trigger
|
|
133
|
+
</div>
|
|
134
|
+
}>
|
|
135
|
+
</DropdownMenu>
|
|
136
|
+
);
|
|
137
|
+
`,
|
|
138
|
+
'should only add comments triggerType prop when trigger is an object',
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
defineInlineTest(
|
|
142
|
+
{ default: transformer, parser: 'tsx' },
|
|
143
|
+
{},
|
|
144
|
+
`
|
|
145
|
+
import React from "react";
|
|
146
|
+
import DropdownMenu from "@atlaskit/dropdown-menu";
|
|
147
|
+
|
|
148
|
+
export default () => (
|
|
149
|
+
<DropdownMenuWrapper>
|
|
150
|
+
<DropdownMenu
|
|
151
|
+
trigger={
|
|
152
|
+
<div>
|
|
153
|
+
<button/> trigger
|
|
154
|
+
</div>
|
|
155
|
+
}>
|
|
156
|
+
</DropdownMenu>
|
|
157
|
+
</DropdownMenuWrapper>
|
|
158
|
+
);
|
|
159
|
+
`,
|
|
160
|
+
`
|
|
161
|
+
import React from "react";
|
|
162
|
+
import DropdownMenu from "@atlaskit/dropdown-menu";
|
|
163
|
+
|
|
164
|
+
export default () => (
|
|
165
|
+
<DropdownMenuWrapper>
|
|
166
|
+
<DropdownMenu
|
|
167
|
+
/* TODO: (from codemod)
|
|
168
|
+
The usage of the 'trigger', 'triggerType' and 'triggerButtonProps' prop in this component could not be transformed and requires manual intervention.
|
|
169
|
+
Since version 11.0.0, we have simplified the API and now only use the 'trigger' prop.
|
|
170
|
+
Please refer to https://hello.atlassian.net/wiki/spaces/DST/pages/1330997516/Dropdown+menu+upgrade+guide for more details.
|
|
171
|
+
And feel free to reach out to us on our support channel if you have more queries – #help-design-system. */
|
|
172
|
+
trigger={
|
|
173
|
+
<div>
|
|
174
|
+
<button/> trigger
|
|
175
|
+
</div>
|
|
176
|
+
}>
|
|
177
|
+
</DropdownMenu>
|
|
178
|
+
</DropdownMenuWrapper>
|
|
179
|
+
);
|
|
180
|
+
`,
|
|
181
|
+
'should only add comments that do not appear on the DOM',
|
|
182
|
+
);
|
|
100
183
|
});
|
|
@@ -9,8 +9,9 @@ import {
|
|
|
9
9
|
|
|
10
10
|
const comment = `
|
|
11
11
|
The usage of the 'trigger', 'triggerType' and 'triggerButtonProps' prop in this component could not be transformed and requires manual intervention.
|
|
12
|
-
Since version 11.0.0, we simplified the API and
|
|
13
|
-
|
|
12
|
+
Since version 11.0.0, we have simplified the API and now only use the 'trigger' prop.
|
|
13
|
+
Please refer to https://hello.atlassian.net/wiki/spaces/DST/pages/1330997516/Dropdown+menu+upgrade+guide for more details.
|
|
14
|
+
And feel free to reach out to us on our support channel if you have more queries – #help-design-system.
|
|
14
15
|
`;
|
|
15
16
|
|
|
16
17
|
const convertTriggerType = (j: core.JSCodeshift, source: Collection<Node>) => {
|
|
@@ -30,8 +31,8 @@ const convertTriggerType = (j: core.JSCodeshift, source: Collection<Node>) => {
|
|
|
30
31
|
const triggerTypeProp = getJSXAttributesByName(j, element, 'triggerType');
|
|
31
32
|
const triggerProp = getJSXAttributesByName(j, element, 'trigger');
|
|
32
33
|
|
|
33
|
-
// just skip when
|
|
34
|
-
if (
|
|
34
|
+
// just skip when trigger is not defined
|
|
35
|
+
if (triggerProp.length === 0) {
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -49,7 +50,15 @@ const convertTriggerType = (j: core.JSCodeshift, source: Collection<Node>) => {
|
|
|
49
50
|
});
|
|
50
51
|
} else {
|
|
51
52
|
// for anything else we left a inline message
|
|
52
|
-
|
|
53
|
+
// Overriding the comment prefix to be 'TODO: (from codemod)'
|
|
54
|
+
// to avoid trailing spaces.
|
|
55
|
+
addCommentBefore(
|
|
56
|
+
j,
|
|
57
|
+
triggerProp,
|
|
58
|
+
comment,
|
|
59
|
+
'block',
|
|
60
|
+
'TODO: (from codemod)',
|
|
61
|
+
);
|
|
53
62
|
}
|
|
54
63
|
});
|
|
55
64
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// eslint-disable-next-line @repo/internal/fs/filename-pattern-match
|
|
2
|
+
import { createRemoveFuncFor } from '@atlaskit/codemod-utils';
|
|
3
|
+
|
|
4
|
+
const deprecateAutoFocus = () => [
|
|
5
|
+
createRemoveFuncFor('@atlaskit/dropdown-menu', 'DropdownItem', 'autoFocus'),
|
|
6
|
+
createRemoveFuncFor(
|
|
7
|
+
'@atlaskit/dropdown-menu',
|
|
8
|
+
'DropdownItemCheckbox',
|
|
9
|
+
'autoFocus',
|
|
10
|
+
),
|
|
11
|
+
createRemoveFuncFor(
|
|
12
|
+
'@atlaskit/dropdown-menu',
|
|
13
|
+
'DropdownItemRadio',
|
|
14
|
+
'autoFocus',
|
|
15
|
+
),
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export default deprecateAutoFocus;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// eslint-disable-next-line @repo/internal/fs/filename-pattern-match
|
|
2
|
+
import { createRemoveFuncAddCommentFor } from '@atlaskit/codemod-utils';
|
|
3
|
+
|
|
4
|
+
const deprecateItems = createRemoveFuncAddCommentFor(
|
|
5
|
+
'@atlaskit/dropdown-menu',
|
|
6
|
+
'boundariesElement',
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export default deprecateItems;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// eslint-disable-next-line @repo/internal/fs/filename-pattern-match
|
|
2
|
+
import { createRemoveFuncFor } from '@atlaskit/codemod-utils';
|
|
3
|
+
|
|
4
|
+
const deprecateIsCompact = () => [
|
|
5
|
+
createRemoveFuncFor('@atlaskit/dropdown-menu', 'DropdownItem', 'isCompact'),
|
|
6
|
+
createRemoveFuncFor(
|
|
7
|
+
'@atlaskit/dropdown-menu',
|
|
8
|
+
'DropdownItemCheckbox',
|
|
9
|
+
'isCompact',
|
|
10
|
+
),
|
|
11
|
+
createRemoveFuncFor(
|
|
12
|
+
'@atlaskit/dropdown-menu',
|
|
13
|
+
'DropdownItemRadio',
|
|
14
|
+
'isCompact',
|
|
15
|
+
),
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export default deprecateIsCompact;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// eslint-disable-next-line @repo/internal/fs/filename-pattern-match
|
|
2
|
+
import { createRemoveFuncFor } from '@atlaskit/codemod-utils';
|
|
3
|
+
|
|
4
|
+
const deprecateIsHidden = () => [
|
|
5
|
+
createRemoveFuncFor('@atlaskit/dropdown-menu', 'DropdownItem', 'isHidden'),
|
|
6
|
+
createRemoveFuncFor(
|
|
7
|
+
'@atlaskit/dropdown-menu',
|
|
8
|
+
'DropdownItemCheckbox',
|
|
9
|
+
'isHidden',
|
|
10
|
+
),
|
|
11
|
+
createRemoveFuncFor(
|
|
12
|
+
'@atlaskit/dropdown-menu',
|
|
13
|
+
'DropdownItemRadio',
|
|
14
|
+
'isHidden',
|
|
15
|
+
),
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export default deprecateIsHidden;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// eslint-disable-next-line @repo/internal/fs/filename-pattern-match
|
|
2
|
+
import { createRemoveFuncAddCommentFor } from '@atlaskit/codemod-utils';
|
|
3
|
+
|
|
4
|
+
const deprecateItems = createRemoveFuncAddCommentFor(
|
|
5
|
+
'@atlaskit/dropdown-menu',
|
|
6
|
+
'isMenuFixed',
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export default deprecateItems;
|
|
@@ -100,7 +100,8 @@ var DropdownItemCheckbox = function DropdownItemCheckbox(props) {
|
|
|
100
100
|
primaryColor: iconColors.primary,
|
|
101
101
|
secondaryColor: iconColors.secondary
|
|
102
102
|
}),
|
|
103
|
-
ref: itemRef
|
|
103
|
+
ref: itemRef // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
104
|
+
|
|
104
105
|
}, rest));
|
|
105
106
|
};
|
|
106
107
|
|
|
@@ -9,6 +9,8 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
11
|
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
|
|
12
14
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
15
|
|
|
14
16
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
@@ -45,7 +47,14 @@ var _menuWrapper = _interopRequireDefault(require("./internal/components/menu-wr
|
|
|
45
47
|
|
|
46
48
|
var _selectionStore = _interopRequireDefault(require("./internal/context/selection-store"));
|
|
47
49
|
|
|
50
|
+
var _useGeneratedId = _interopRequireDefault(require("./internal/utils/use-generated-id"));
|
|
51
|
+
|
|
48
52
|
var _excluded = ["ref"];
|
|
53
|
+
|
|
54
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
55
|
+
|
|
56
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
57
|
+
|
|
49
58
|
var gridSize = (0, _constants.gridSize)();
|
|
50
59
|
var spinnerContainerStyles = (0, _core.css)({
|
|
51
60
|
display: 'flex',
|
|
@@ -54,6 +63,7 @@ var spinnerContainerStyles = (0, _core.css)({
|
|
|
54
63
|
justifyContent: 'center'
|
|
55
64
|
});
|
|
56
65
|
var MAX_HEIGHT = "calc(100vh - ".concat(gridSize * 2, "px)");
|
|
66
|
+
var fallbackPlacements = ['bottom', 'bottom-end', 'right-start', 'left-start', 'auto'];
|
|
57
67
|
/**
|
|
58
68
|
* __Dropdown menu__
|
|
59
69
|
*
|
|
@@ -73,7 +83,7 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
73
83
|
children = props.children,
|
|
74
84
|
_props$placement = props.placement,
|
|
75
85
|
placement = _props$placement === void 0 ? 'bottom-start' : _props$placement,
|
|
76
|
-
|
|
86
|
+
_trigger = props.trigger,
|
|
77
87
|
_props$shouldFlip = props.shouldFlip,
|
|
78
88
|
shouldFlip = _props$shouldFlip === void 0 ? true : _props$shouldFlip,
|
|
79
89
|
_props$isLoading = props.isLoading,
|
|
@@ -82,7 +92,9 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
82
92
|
autoFocus = _props$autoFocus === void 0 ? false : _props$autoFocus,
|
|
83
93
|
testId = props.testId,
|
|
84
94
|
_props$statusLabel = props.statusLabel,
|
|
85
|
-
statusLabel = _props$statusLabel === void 0 ? 'Loading' : _props$statusLabel
|
|
95
|
+
statusLabel = _props$statusLabel === void 0 ? 'Loading' : _props$statusLabel,
|
|
96
|
+
_props$zIndex = props.zIndex,
|
|
97
|
+
zIndex = _props$zIndex === void 0 ? _constants.layers.modal() : _props$zIndex;
|
|
86
98
|
|
|
87
99
|
var _useControlledState = (0, _useControlled.default)(isOpen, function () {
|
|
88
100
|
return defaultOpen;
|
|
@@ -137,41 +149,43 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
137
149
|
};
|
|
138
150
|
|
|
139
151
|
(0, _useKeydownEvent.default)(handleDownArrow, isFocused);
|
|
140
|
-
|
|
141
|
-
var renderTrigger = function renderTrigger(triggerProps) {
|
|
142
|
-
if (typeof Trigger === 'function') {
|
|
143
|
-
var ref = triggerProps.ref,
|
|
144
|
-
providedProps = (0, _objectWithoutProperties2.default)(triggerProps, _excluded);
|
|
145
|
-
return (0, _core.jsx)(Trigger, (0, _extends2.default)({}, providedProps, bindFocus, {
|
|
146
|
-
triggerRef: ref,
|
|
147
|
-
isSelected: isLocalOpen,
|
|
148
|
-
onClick: handleTriggerClicked,
|
|
149
|
-
testId: testId && "".concat(testId, "--trigger")
|
|
150
|
-
}));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return (0, _core.jsx)(_standardButton.default, (0, _extends2.default)({}, triggerProps, bindFocus, {
|
|
154
|
-
isSelected: isLocalOpen,
|
|
155
|
-
iconAfter: (0, _core.jsx)(_chevronDown.default, {
|
|
156
|
-
size: "medium",
|
|
157
|
-
label: "expand"
|
|
158
|
-
}),
|
|
159
|
-
onClick: handleTriggerClicked,
|
|
160
|
-
testId: testId && "".concat(testId, "--trigger")
|
|
161
|
-
}), Trigger);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
var fallbackPlacements = ['bottom', 'bottom-end', 'right-start', 'left-start', 'auto'];
|
|
152
|
+
var id = (0, _useGeneratedId.default)();
|
|
165
153
|
return (0, _core.jsx)(_selectionStore.default, null, (0, _core.jsx)(_popup.default, {
|
|
154
|
+
id: isLocalOpen ? id : undefined,
|
|
166
155
|
shouldFlip: shouldFlip,
|
|
167
156
|
isOpen: isLocalOpen,
|
|
168
157
|
onClose: handleOnClose,
|
|
169
|
-
zIndex:
|
|
158
|
+
zIndex: zIndex,
|
|
170
159
|
placement: placement,
|
|
171
160
|
fallbackPlacements: fallbackPlacements,
|
|
172
161
|
testId: testId && "".concat(testId, "--content"),
|
|
173
|
-
trigger: renderTrigger,
|
|
174
162
|
shouldUseCaptureOnOutsideClick: true,
|
|
163
|
+
trigger: function trigger(triggerProps) {
|
|
164
|
+
if (typeof _trigger === 'function') {
|
|
165
|
+
var ref = triggerProps.ref,
|
|
166
|
+
providedProps = (0, _objectWithoutProperties2.default)(triggerProps, _excluded);
|
|
167
|
+
return _trigger(_objectSpread(_objectSpread(_objectSpread({}, providedProps), bindFocus), {}, {
|
|
168
|
+
triggerRef: ref,
|
|
169
|
+
isSelected: isLocalOpen,
|
|
170
|
+
onClick: handleTriggerClicked,
|
|
171
|
+
testId: testId && "".concat(testId, "--trigger")
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return (0, _core.jsx)(_standardButton.default, (0, _extends2.default)({}, bindFocus, {
|
|
176
|
+
ref: triggerProps.ref,
|
|
177
|
+
"aria-controls": triggerProps['aria-controls'],
|
|
178
|
+
"aria-expanded": triggerProps['aria-expanded'],
|
|
179
|
+
"aria-haspopup": triggerProps['aria-haspopup'],
|
|
180
|
+
isSelected: isLocalOpen,
|
|
181
|
+
iconAfter: (0, _core.jsx)(_chevronDown.default, {
|
|
182
|
+
size: "medium",
|
|
183
|
+
label: "expand"
|
|
184
|
+
}),
|
|
185
|
+
onClick: handleTriggerClicked,
|
|
186
|
+
testId: testId && "".concat(testId, "--trigger")
|
|
187
|
+
}), _trigger);
|
|
188
|
+
},
|
|
175
189
|
content: function content(_ref) {
|
|
176
190
|
var setInitialFocusRef = _ref.setInitialFocusRef;
|
|
177
191
|
return (0, _core.jsx)(_focusManager.default, null, (0, _core.jsx)(_menuWrapper.default, {
|
|
@@ -58,8 +58,10 @@ var MenuWrapper = function MenuWrapper(_ref) {
|
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
setInitialFocusRef && setInitialFocusRef(menuItemRefs[0]);
|
|
61
|
+
setInitialFocusRef && setInitialFocusRef(menuItemRefs[0]); // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
62
|
+
|
|
62
63
|
return /*#__PURE__*/_react.default.createElement(_menuGroup.default, (0, _extends2.default)({
|
|
64
|
+
role: "menu",
|
|
63
65
|
onClick: closeOnMenuItemClick
|
|
64
66
|
}, props));
|
|
65
67
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useGeneratedId;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var PREFIX = 'ds--dropdown--';
|
|
11
|
+
|
|
12
|
+
var generateRandomString = function generateRandomString() {
|
|
13
|
+
return (// This string is used only on client side usually triggered after a user interaction.
|
|
14
|
+
// Therefore, so there is no risk of mismatch
|
|
15
|
+
// between server and client generated markup.
|
|
16
|
+
// eslint-disable-next-line @repo/internal/react/disallow-unstable-values
|
|
17
|
+
"".concat(PREFIX).concat(Math.random().toString(16).substr(2, 8))
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* useGeneratedId generates a random string which remains constant across
|
|
22
|
+
* renders when called without any parameter.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function useGeneratedId() {
|
|
27
|
+
var cachedId = (0, _react.useRef)(generateRandomString());
|
|
28
|
+
return cachedId.current;
|
|
29
|
+
}
|
|
@@ -100,7 +100,8 @@ var DropdownItemRadio = function DropdownItemRadio(props) {
|
|
|
100
100
|
primaryColor: iconColors.primary,
|
|
101
101
|
secondaryColor: iconColors.secondary
|
|
102
102
|
}),
|
|
103
|
-
ref: itemRef
|
|
103
|
+
ref: itemRef // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
104
|
+
|
|
104
105
|
}, rest));
|
|
105
106
|
};
|
|
106
107
|
|
package/dist/cjs/version.json
CHANGED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
6
|
+
|
|
7
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
8
|
+
|
|
9
|
+
var _helper = require("@atlaskit/visual-regression/helper");
|
|
10
|
+
|
|
11
|
+
var dropdownTrigger = '[data-testid="dropdown--trigger"]';
|
|
12
|
+
var dropdownContent = '[data-testid="dropdown--content"]';
|
|
13
|
+
describe('Snapshot Test', function () {
|
|
14
|
+
it('it should match visual snapshot for dropdown', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
15
|
+
var url, _global, page, dropdownImage;
|
|
16
|
+
|
|
17
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
18
|
+
while (1) {
|
|
19
|
+
switch (_context.prev = _context.next) {
|
|
20
|
+
case 0:
|
|
21
|
+
url = (0, _helper.getExampleUrl)('design-system', 'dropdown-menu', 'default-dropdown-menu', global.__BASEURL__);
|
|
22
|
+
_global = global, page = _global.page;
|
|
23
|
+
_context.next = 4;
|
|
24
|
+
return (0, _helper.loadPage)(page, url);
|
|
25
|
+
|
|
26
|
+
case 4:
|
|
27
|
+
_context.next = 6;
|
|
28
|
+
return page.waitForSelector(dropdownContent);
|
|
29
|
+
|
|
30
|
+
case 6:
|
|
31
|
+
_context.next = 8;
|
|
32
|
+
return page.screenshot();
|
|
33
|
+
|
|
34
|
+
case 8:
|
|
35
|
+
dropdownImage = _context.sent;
|
|
36
|
+
expect(dropdownImage).toMatchProdImageSnapshot();
|
|
37
|
+
|
|
38
|
+
case 10:
|
|
39
|
+
case "end":
|
|
40
|
+
return _context.stop();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, _callee);
|
|
44
|
+
})));
|
|
45
|
+
it('should accept custom zIndex', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
46
|
+
var url, _global2, page, button, popupImage;
|
|
47
|
+
|
|
48
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
49
|
+
while (1) {
|
|
50
|
+
switch (_context2.prev = _context2.next) {
|
|
51
|
+
case 0:
|
|
52
|
+
url = (0, _helper.getExampleUrl)('design-system', 'dropdown-menu', 'setting-z-index', global.__BASEURL__);
|
|
53
|
+
_global2 = global, page = _global2.page;
|
|
54
|
+
button = "[data-testid='popup--trigger']";
|
|
55
|
+
_context2.next = 5;
|
|
56
|
+
return (0, _helper.loadPage)(page, url);
|
|
57
|
+
|
|
58
|
+
case 5:
|
|
59
|
+
_context2.next = 7;
|
|
60
|
+
return page.waitForSelector(button);
|
|
61
|
+
|
|
62
|
+
case 7:
|
|
63
|
+
_context2.next = 9;
|
|
64
|
+
return page.click(button);
|
|
65
|
+
|
|
66
|
+
case 9:
|
|
67
|
+
_context2.next = 11;
|
|
68
|
+
return page.waitForSelector(dropdownTrigger);
|
|
69
|
+
|
|
70
|
+
case 11:
|
|
71
|
+
_context2.next = 13;
|
|
72
|
+
return page.click(dropdownTrigger);
|
|
73
|
+
|
|
74
|
+
case 13:
|
|
75
|
+
_context2.next = 15;
|
|
76
|
+
return page.waitForSelector(dropdownContent);
|
|
77
|
+
|
|
78
|
+
case 15:
|
|
79
|
+
_context2.next = 17;
|
|
80
|
+
return page.screenshot();
|
|
81
|
+
|
|
82
|
+
case 17:
|
|
83
|
+
popupImage = _context2.sent;
|
|
84
|
+
expect(popupImage).toMatchProdImageSnapshot();
|
|
85
|
+
|
|
86
|
+
case 19:
|
|
87
|
+
case "end":
|
|
88
|
+
return _context2.stop();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}, _callee2);
|
|
92
|
+
})));
|
|
93
|
+
});
|
|
@@ -17,6 +17,7 @@ import VisuallyHidden from '@atlaskit/visually-hidden';
|
|
|
17
17
|
import FocusManager from './internal/components/focus-manager';
|
|
18
18
|
import MenuWrapper from './internal/components/menu-wrapper';
|
|
19
19
|
import SelectionStore from './internal/context/selection-store';
|
|
20
|
+
import useGeneratedId from './internal/utils/use-generated-id';
|
|
20
21
|
const gridSize = gridSizeFn();
|
|
21
22
|
const spinnerContainerStyles = css({
|
|
22
23
|
display: 'flex',
|
|
@@ -25,6 +26,7 @@ const spinnerContainerStyles = css({
|
|
|
25
26
|
justifyContent: 'center'
|
|
26
27
|
});
|
|
27
28
|
const MAX_HEIGHT = `calc(100vh - ${gridSize * 2}px)`;
|
|
29
|
+
const fallbackPlacements = ['bottom', 'bottom-end', 'right-start', 'left-start', 'auto'];
|
|
28
30
|
/**
|
|
29
31
|
* __Dropdown menu__
|
|
30
32
|
*
|
|
@@ -42,12 +44,13 @@ const DropdownMenu = props => {
|
|
|
42
44
|
onOpenChange = noop,
|
|
43
45
|
children,
|
|
44
46
|
placement = 'bottom-start',
|
|
45
|
-
trigger
|
|
47
|
+
trigger,
|
|
46
48
|
shouldFlip = true,
|
|
47
49
|
isLoading = false,
|
|
48
50
|
autoFocus = false,
|
|
49
51
|
testId,
|
|
50
|
-
statusLabel = 'Loading'
|
|
52
|
+
statusLabel = 'Loading',
|
|
53
|
+
zIndex = layers.modal()
|
|
51
54
|
} = props;
|
|
52
55
|
const [isLocalOpen, setLocalIsOpen] = useControlledState(isOpen, () => defaultOpen);
|
|
53
56
|
const [isTriggeredUsingKeyboard, setTriggeredUsingKeyboard] = useState(false);
|
|
@@ -94,43 +97,46 @@ const DropdownMenu = props => {
|
|
|
94
97
|
};
|
|
95
98
|
|
|
96
99
|
useKeydownEvent(handleDownArrow, isFocused);
|
|
97
|
-
|
|
98
|
-
const renderTrigger = triggerProps => {
|
|
99
|
-
if (typeof Trigger === 'function') {
|
|
100
|
-
const {
|
|
101
|
-
ref,
|
|
102
|
-
...providedProps
|
|
103
|
-
} = triggerProps;
|
|
104
|
-
return jsx(Trigger, _extends({}, providedProps, bindFocus, {
|
|
105
|
-
triggerRef: ref,
|
|
106
|
-
isSelected: isLocalOpen,
|
|
107
|
-
onClick: handleTriggerClicked,
|
|
108
|
-
testId: testId && `${testId}--trigger`
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return jsx(Button, _extends({}, triggerProps, bindFocus, {
|
|
113
|
-
isSelected: isLocalOpen,
|
|
114
|
-
iconAfter: jsx(ExpandIcon, {
|
|
115
|
-
size: "medium",
|
|
116
|
-
label: "expand"
|
|
117
|
-
}),
|
|
118
|
-
onClick: handleTriggerClicked,
|
|
119
|
-
testId: testId && `${testId}--trigger`
|
|
120
|
-
}), Trigger);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const fallbackPlacements = ['bottom', 'bottom-end', 'right-start', 'left-start', 'auto'];
|
|
100
|
+
const id = useGeneratedId();
|
|
124
101
|
return jsx(SelectionStore, null, jsx(Popup, {
|
|
102
|
+
id: isLocalOpen ? id : undefined,
|
|
125
103
|
shouldFlip: shouldFlip,
|
|
126
104
|
isOpen: isLocalOpen,
|
|
127
105
|
onClose: handleOnClose,
|
|
128
|
-
zIndex:
|
|
106
|
+
zIndex: zIndex,
|
|
129
107
|
placement: placement,
|
|
130
108
|
fallbackPlacements: fallbackPlacements,
|
|
131
109
|
testId: testId && `${testId}--content`,
|
|
132
|
-
trigger: renderTrigger,
|
|
133
110
|
shouldUseCaptureOnOutsideClick: true,
|
|
111
|
+
trigger: triggerProps => {
|
|
112
|
+
if (typeof trigger === 'function') {
|
|
113
|
+
const {
|
|
114
|
+
ref,
|
|
115
|
+
...providedProps
|
|
116
|
+
} = triggerProps;
|
|
117
|
+
return trigger({ ...providedProps,
|
|
118
|
+
...bindFocus,
|
|
119
|
+
triggerRef: ref,
|
|
120
|
+
isSelected: isLocalOpen,
|
|
121
|
+
onClick: handleTriggerClicked,
|
|
122
|
+
testId: testId && `${testId}--trigger`
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return jsx(Button, _extends({}, bindFocus, {
|
|
127
|
+
ref: triggerProps.ref,
|
|
128
|
+
"aria-controls": triggerProps['aria-controls'],
|
|
129
|
+
"aria-expanded": triggerProps['aria-expanded'],
|
|
130
|
+
"aria-haspopup": triggerProps['aria-haspopup'],
|
|
131
|
+
isSelected: isLocalOpen,
|
|
132
|
+
iconAfter: jsx(ExpandIcon, {
|
|
133
|
+
size: "medium",
|
|
134
|
+
label: "expand"
|
|
135
|
+
}),
|
|
136
|
+
onClick: handleTriggerClicked,
|
|
137
|
+
testId: testId && `${testId}--trigger`
|
|
138
|
+
}), trigger);
|
|
139
|
+
},
|
|
134
140
|
content: ({
|
|
135
141
|
setInitialFocusRef
|
|
136
142
|
}) => jsx(FocusManager, null, jsx(MenuWrapper, {
|
|
@@ -35,8 +35,10 @@ const MenuWrapper = ({
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
setInitialFocusRef && setInitialFocusRef(menuItemRefs[0]);
|
|
38
|
+
setInitialFocusRef && setInitialFocusRef(menuItemRefs[0]); // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
39
|
+
|
|
39
40
|
return /*#__PURE__*/React.createElement(MenuGroup, _extends({
|
|
41
|
+
role: "menu",
|
|
40
42
|
onClick: closeOnMenuItemClick
|
|
41
43
|
}, props));
|
|
42
44
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
const PREFIX = 'ds--dropdown--';
|
|
3
|
+
|
|
4
|
+
const generateRandomString = () => // This string is used only on client side usually triggered after a user interaction.
|
|
5
|
+
// Therefore, so there is no risk of mismatch
|
|
6
|
+
// between server and client generated markup.
|
|
7
|
+
// eslint-disable-next-line @repo/internal/react/disallow-unstable-values
|
|
8
|
+
`${PREFIX}${Math.random().toString(16).substr(2, 8)}`;
|
|
9
|
+
/**
|
|
10
|
+
* useGeneratedId generates a random string which remains constant across
|
|
11
|
+
* renders when called without any parameter.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export default function useGeneratedId() {
|
|
16
|
+
const cachedId = useRef(generateRandomString());
|
|
17
|
+
return cachedId.current;
|
|
18
|
+
}
|
package/dist/es2019/version.json
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getExampleUrl, loadPage } from '@atlaskit/visual-regression/helper';
|
|
2
|
+
const dropdownTrigger = '[data-testid="dropdown--trigger"]';
|
|
3
|
+
const dropdownContent = '[data-testid="dropdown--content"]';
|
|
4
|
+
describe('Snapshot Test', () => {
|
|
5
|
+
it('it should match visual snapshot for dropdown', async () => {
|
|
6
|
+
const url = getExampleUrl('design-system', 'dropdown-menu', 'default-dropdown-menu', global.__BASEURL__);
|
|
7
|
+
const {
|
|
8
|
+
page
|
|
9
|
+
} = global;
|
|
10
|
+
await loadPage(page, url);
|
|
11
|
+
await page.waitForSelector(dropdownContent);
|
|
12
|
+
const dropdownImage = await page.screenshot();
|
|
13
|
+
expect(dropdownImage).toMatchProdImageSnapshot();
|
|
14
|
+
});
|
|
15
|
+
it('should accept custom zIndex', async () => {
|
|
16
|
+
const url = getExampleUrl('design-system', 'dropdown-menu', 'setting-z-index', global.__BASEURL__);
|
|
17
|
+
const {
|
|
18
|
+
page
|
|
19
|
+
} = global;
|
|
20
|
+
const button = "[data-testid='popup--trigger']";
|
|
21
|
+
await loadPage(page, url);
|
|
22
|
+
await page.waitForSelector(button);
|
|
23
|
+
await page.click(button);
|
|
24
|
+
await page.waitForSelector(dropdownTrigger);
|
|
25
|
+
await page.click(dropdownTrigger);
|
|
26
|
+
await page.waitForSelector(dropdownContent);
|
|
27
|
+
const popupImage = await page.screenshot();
|
|
28
|
+
expect(popupImage).toMatchProdImageSnapshot();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -74,7 +74,8 @@ var DropdownItemCheckbox = function DropdownItemCheckbox(props) {
|
|
|
74
74
|
primaryColor: iconColors.primary,
|
|
75
75
|
secondaryColor: iconColors.secondary
|
|
76
76
|
}),
|
|
77
|
-
ref: itemRef
|
|
77
|
+
ref: itemRef // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
78
|
+
|
|
78
79
|
}, rest));
|
|
79
80
|
};
|
|
80
81
|
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
4
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
5
|
var _excluded = ["ref"];
|
|
5
6
|
|
|
7
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
8
|
+
|
|
9
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
+
|
|
6
11
|
/** @jsx jsx */
|
|
7
12
|
import { useCallback, useState } from 'react';
|
|
8
13
|
import { css, jsx } from '@emotion/core';
|
|
@@ -20,6 +25,7 @@ import VisuallyHidden from '@atlaskit/visually-hidden';
|
|
|
20
25
|
import FocusManager from './internal/components/focus-manager';
|
|
21
26
|
import MenuWrapper from './internal/components/menu-wrapper';
|
|
22
27
|
import SelectionStore from './internal/context/selection-store';
|
|
28
|
+
import useGeneratedId from './internal/utils/use-generated-id';
|
|
23
29
|
var gridSize = gridSizeFn();
|
|
24
30
|
var spinnerContainerStyles = css({
|
|
25
31
|
display: 'flex',
|
|
@@ -28,6 +34,7 @@ var spinnerContainerStyles = css({
|
|
|
28
34
|
justifyContent: 'center'
|
|
29
35
|
});
|
|
30
36
|
var MAX_HEIGHT = "calc(100vh - ".concat(gridSize * 2, "px)");
|
|
37
|
+
var fallbackPlacements = ['bottom', 'bottom-end', 'right-start', 'left-start', 'auto'];
|
|
31
38
|
/**
|
|
32
39
|
* __Dropdown menu__
|
|
33
40
|
*
|
|
@@ -47,7 +54,7 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
47
54
|
children = props.children,
|
|
48
55
|
_props$placement = props.placement,
|
|
49
56
|
placement = _props$placement === void 0 ? 'bottom-start' : _props$placement,
|
|
50
|
-
|
|
57
|
+
_trigger = props.trigger,
|
|
51
58
|
_props$shouldFlip = props.shouldFlip,
|
|
52
59
|
shouldFlip = _props$shouldFlip === void 0 ? true : _props$shouldFlip,
|
|
53
60
|
_props$isLoading = props.isLoading,
|
|
@@ -56,7 +63,9 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
56
63
|
autoFocus = _props$autoFocus === void 0 ? false : _props$autoFocus,
|
|
57
64
|
testId = props.testId,
|
|
58
65
|
_props$statusLabel = props.statusLabel,
|
|
59
|
-
statusLabel = _props$statusLabel === void 0 ? 'Loading' : _props$statusLabel
|
|
66
|
+
statusLabel = _props$statusLabel === void 0 ? 'Loading' : _props$statusLabel,
|
|
67
|
+
_props$zIndex = props.zIndex,
|
|
68
|
+
zIndex = _props$zIndex === void 0 ? layers.modal() : _props$zIndex;
|
|
60
69
|
|
|
61
70
|
var _useControlledState = useControlledState(isOpen, function () {
|
|
62
71
|
return defaultOpen;
|
|
@@ -111,42 +120,44 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
111
120
|
};
|
|
112
121
|
|
|
113
122
|
useKeydownEvent(handleDownArrow, isFocused);
|
|
114
|
-
|
|
115
|
-
var renderTrigger = function renderTrigger(triggerProps) {
|
|
116
|
-
if (typeof Trigger === 'function') {
|
|
117
|
-
var ref = triggerProps.ref,
|
|
118
|
-
providedProps = _objectWithoutProperties(triggerProps, _excluded);
|
|
119
|
-
|
|
120
|
-
return jsx(Trigger, _extends({}, providedProps, bindFocus, {
|
|
121
|
-
triggerRef: ref,
|
|
122
|
-
isSelected: isLocalOpen,
|
|
123
|
-
onClick: handleTriggerClicked,
|
|
124
|
-
testId: testId && "".concat(testId, "--trigger")
|
|
125
|
-
}));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return jsx(Button, _extends({}, triggerProps, bindFocus, {
|
|
129
|
-
isSelected: isLocalOpen,
|
|
130
|
-
iconAfter: jsx(ExpandIcon, {
|
|
131
|
-
size: "medium",
|
|
132
|
-
label: "expand"
|
|
133
|
-
}),
|
|
134
|
-
onClick: handleTriggerClicked,
|
|
135
|
-
testId: testId && "".concat(testId, "--trigger")
|
|
136
|
-
}), Trigger);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
var fallbackPlacements = ['bottom', 'bottom-end', 'right-start', 'left-start', 'auto'];
|
|
123
|
+
var id = useGeneratedId();
|
|
140
124
|
return jsx(SelectionStore, null, jsx(Popup, {
|
|
125
|
+
id: isLocalOpen ? id : undefined,
|
|
141
126
|
shouldFlip: shouldFlip,
|
|
142
127
|
isOpen: isLocalOpen,
|
|
143
128
|
onClose: handleOnClose,
|
|
144
|
-
zIndex:
|
|
129
|
+
zIndex: zIndex,
|
|
145
130
|
placement: placement,
|
|
146
131
|
fallbackPlacements: fallbackPlacements,
|
|
147
132
|
testId: testId && "".concat(testId, "--content"),
|
|
148
|
-
trigger: renderTrigger,
|
|
149
133
|
shouldUseCaptureOnOutsideClick: true,
|
|
134
|
+
trigger: function trigger(triggerProps) {
|
|
135
|
+
if (typeof _trigger === 'function') {
|
|
136
|
+
var ref = triggerProps.ref,
|
|
137
|
+
providedProps = _objectWithoutProperties(triggerProps, _excluded);
|
|
138
|
+
|
|
139
|
+
return _trigger(_objectSpread(_objectSpread(_objectSpread({}, providedProps), bindFocus), {}, {
|
|
140
|
+
triggerRef: ref,
|
|
141
|
+
isSelected: isLocalOpen,
|
|
142
|
+
onClick: handleTriggerClicked,
|
|
143
|
+
testId: testId && "".concat(testId, "--trigger")
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return jsx(Button, _extends({}, bindFocus, {
|
|
148
|
+
ref: triggerProps.ref,
|
|
149
|
+
"aria-controls": triggerProps['aria-controls'],
|
|
150
|
+
"aria-expanded": triggerProps['aria-expanded'],
|
|
151
|
+
"aria-haspopup": triggerProps['aria-haspopup'],
|
|
152
|
+
isSelected: isLocalOpen,
|
|
153
|
+
iconAfter: jsx(ExpandIcon, {
|
|
154
|
+
size: "medium",
|
|
155
|
+
label: "expand"
|
|
156
|
+
}),
|
|
157
|
+
onClick: handleTriggerClicked,
|
|
158
|
+
testId: testId && "".concat(testId, "--trigger")
|
|
159
|
+
}), _trigger);
|
|
160
|
+
},
|
|
150
161
|
content: function content(_ref) {
|
|
151
162
|
var setInitialFocusRef = _ref.setInitialFocusRef;
|
|
152
163
|
return jsx(FocusManager, null, jsx(MenuWrapper, {
|
|
@@ -36,8 +36,10 @@ var MenuWrapper = function MenuWrapper(_ref) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
setInitialFocusRef && setInitialFocusRef(menuItemRefs[0]);
|
|
39
|
+
setInitialFocusRef && setInitialFocusRef(menuItemRefs[0]); // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
40
|
+
|
|
40
41
|
return /*#__PURE__*/React.createElement(MenuGroup, _extends({
|
|
42
|
+
role: "menu",
|
|
41
43
|
onClick: closeOnMenuItemClick
|
|
42
44
|
}, props));
|
|
43
45
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
var PREFIX = 'ds--dropdown--';
|
|
3
|
+
|
|
4
|
+
var generateRandomString = function generateRandomString() {
|
|
5
|
+
return (// This string is used only on client side usually triggered after a user interaction.
|
|
6
|
+
// Therefore, so there is no risk of mismatch
|
|
7
|
+
// between server and client generated markup.
|
|
8
|
+
// eslint-disable-next-line @repo/internal/react/disallow-unstable-values
|
|
9
|
+
"".concat(PREFIX).concat(Math.random().toString(16).substr(2, 8))
|
|
10
|
+
);
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* useGeneratedId generates a random string which remains constant across
|
|
14
|
+
* renders when called without any parameter.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export default function useGeneratedId() {
|
|
19
|
+
var cachedId = useRef(generateRandomString());
|
|
20
|
+
return cachedId.current;
|
|
21
|
+
}
|
|
@@ -74,7 +74,8 @@ var DropdownItemRadio = function DropdownItemRadio(props) {
|
|
|
74
74
|
primaryColor: iconColors.primary,
|
|
75
75
|
secondaryColor: iconColors.secondary
|
|
76
76
|
}),
|
|
77
|
-
ref: itemRef
|
|
77
|
+
ref: itemRef // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
78
|
+
|
|
78
79
|
}, rest));
|
|
79
80
|
};
|
|
80
81
|
|
package/dist/esm/version.json
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import { getExampleUrl, loadPage } from '@atlaskit/visual-regression/helper';
|
|
4
|
+
var dropdownTrigger = '[data-testid="dropdown--trigger"]';
|
|
5
|
+
var dropdownContent = '[data-testid="dropdown--content"]';
|
|
6
|
+
describe('Snapshot Test', function () {
|
|
7
|
+
it('it should match visual snapshot for dropdown', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
8
|
+
var url, _global, page, dropdownImage;
|
|
9
|
+
|
|
10
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
11
|
+
while (1) {
|
|
12
|
+
switch (_context.prev = _context.next) {
|
|
13
|
+
case 0:
|
|
14
|
+
url = getExampleUrl('design-system', 'dropdown-menu', 'default-dropdown-menu', global.__BASEURL__);
|
|
15
|
+
_global = global, page = _global.page;
|
|
16
|
+
_context.next = 4;
|
|
17
|
+
return loadPage(page, url);
|
|
18
|
+
|
|
19
|
+
case 4:
|
|
20
|
+
_context.next = 6;
|
|
21
|
+
return page.waitForSelector(dropdownContent);
|
|
22
|
+
|
|
23
|
+
case 6:
|
|
24
|
+
_context.next = 8;
|
|
25
|
+
return page.screenshot();
|
|
26
|
+
|
|
27
|
+
case 8:
|
|
28
|
+
dropdownImage = _context.sent;
|
|
29
|
+
expect(dropdownImage).toMatchProdImageSnapshot();
|
|
30
|
+
|
|
31
|
+
case 10:
|
|
32
|
+
case "end":
|
|
33
|
+
return _context.stop();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, _callee);
|
|
37
|
+
})));
|
|
38
|
+
it('should accept custom zIndex', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
39
|
+
var url, _global2, page, button, popupImage;
|
|
40
|
+
|
|
41
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
42
|
+
while (1) {
|
|
43
|
+
switch (_context2.prev = _context2.next) {
|
|
44
|
+
case 0:
|
|
45
|
+
url = getExampleUrl('design-system', 'dropdown-menu', 'setting-z-index', global.__BASEURL__);
|
|
46
|
+
_global2 = global, page = _global2.page;
|
|
47
|
+
button = "[data-testid='popup--trigger']";
|
|
48
|
+
_context2.next = 5;
|
|
49
|
+
return loadPage(page, url);
|
|
50
|
+
|
|
51
|
+
case 5:
|
|
52
|
+
_context2.next = 7;
|
|
53
|
+
return page.waitForSelector(button);
|
|
54
|
+
|
|
55
|
+
case 7:
|
|
56
|
+
_context2.next = 9;
|
|
57
|
+
return page.click(button);
|
|
58
|
+
|
|
59
|
+
case 9:
|
|
60
|
+
_context2.next = 11;
|
|
61
|
+
return page.waitForSelector(dropdownTrigger);
|
|
62
|
+
|
|
63
|
+
case 11:
|
|
64
|
+
_context2.next = 13;
|
|
65
|
+
return page.click(dropdownTrigger);
|
|
66
|
+
|
|
67
|
+
case 13:
|
|
68
|
+
_context2.next = 15;
|
|
69
|
+
return page.waitForSelector(dropdownContent);
|
|
70
|
+
|
|
71
|
+
case 15:
|
|
72
|
+
_context2.next = 17;
|
|
73
|
+
return page.screenshot();
|
|
74
|
+
|
|
75
|
+
case 17:
|
|
76
|
+
popupImage = _context2.sent;
|
|
77
|
+
expect(popupImage).toMatchProdImageSnapshot();
|
|
78
|
+
|
|
79
|
+
case 19:
|
|
80
|
+
case "end":
|
|
81
|
+
return _context2.stop();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}, _callee2);
|
|
85
|
+
})));
|
|
86
|
+
});
|
package/dist/types/types.d.ts
CHANGED
|
@@ -113,6 +113,12 @@ export interface DropdownMenuProps {
|
|
|
113
113
|
* Called when the menu should be open/closed. Receives an object with `isOpen` state.
|
|
114
114
|
*/
|
|
115
115
|
onOpenChange?: (args: OnOpenChangeArgs) => void;
|
|
116
|
+
/**
|
|
117
|
+
* Z-index that the popup should be displayed in.
|
|
118
|
+
* This is passed to the portal component.
|
|
119
|
+
* Defaults to `layers.modal()` from `@atlaskit/theme` which is 510.
|
|
120
|
+
*/
|
|
121
|
+
zIndex?: number;
|
|
116
122
|
}
|
|
117
123
|
export interface DropdownItemProps {
|
|
118
124
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/dropdown-menu",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.1.2",
|
|
4
4
|
"description": "A dropdown menu displays a list of actions or options to a user.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@atlaskit/button": "^16.
|
|
25
|
+
"@atlaskit/button": "^16.2.0",
|
|
26
26
|
"@atlaskit/codemod-utils": "^3.2.0",
|
|
27
|
-
"@atlaskit/ds-lib": "^1.
|
|
27
|
+
"@atlaskit/ds-lib": "^1.4.0",
|
|
28
28
|
"@atlaskit/icon": "^21.10.0",
|
|
29
|
-
"@atlaskit/menu": "^1.
|
|
29
|
+
"@atlaskit/menu": "^1.3.0",
|
|
30
30
|
"@atlaskit/popup": "^1.3.0",
|
|
31
31
|
"@atlaskit/spinner": "^15.0.0",
|
|
32
32
|
"@atlaskit/theme": "^12.1.0",
|
|
33
|
-
"@atlaskit/tokens": "^0.
|
|
34
|
-
"@atlaskit/visually-hidden": "^0.
|
|
33
|
+
"@atlaskit/tokens": "^0.8.0",
|
|
34
|
+
"@atlaskit/visually-hidden": "^1.0.0",
|
|
35
35
|
"@babel/runtime": "^7.0.0",
|
|
36
36
|
"@emotion/core": "^10.0.9"
|
|
37
37
|
},
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@atlaskit/avatar": "^20.5.0",
|
|
44
44
|
"@atlaskit/docs": "*",
|
|
45
|
-
"@atlaskit/lozenge": "11.1.
|
|
45
|
+
"@atlaskit/lozenge": "11.1.8",
|
|
46
46
|
"@atlaskit/modal-dialog": "^12.2.0",
|
|
47
47
|
"@atlaskit/section-message": "^6.1.0",
|
|
48
48
|
"@atlaskit/ssr": "*",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"@testing-library/react": "^8.0.1",
|
|
55
55
|
"@testing-library/react-hooks": "^1.0.4",
|
|
56
56
|
"jscodeshift": "^0.13.0",
|
|
57
|
+
"raf-stub": "^2.0.1",
|
|
57
58
|
"react-dom": "^16.8.0",
|
|
58
59
|
"storybook-addon-performance": "^0.16.0",
|
|
59
60
|
"tiny-invariant": "^1.2.0",
|