@atlaskit/dropdown-menu 13.0.1 → 13.0.3

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/dropdown-menu
2
2
 
3
+ ## 13.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#124030](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/124030)
8
+ [`6b06882581bfa`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6b06882581bfa) -
9
+ Fix keyboard navigation bug with disabled options
10
+
11
+ ## 13.0.2
12
+
13
+ ### Patch Changes
14
+
15
+ - [#120592](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/120592)
16
+ [`1a5daeece05cf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1a5daeece05cf) -
17
+ Fixes bugs with keyboard navigation in dropdown menu
18
+ - Updated dependencies
19
+
3
20
  ## 13.0.1
4
21
 
5
22
  ### Patch Changes
@@ -18,11 +18,26 @@ var actionMap = (0, _defineProperty2.default)((0, _defineProperty2.default)((0,
18
18
  * return undefined.
19
19
  */
20
20
  var getNextFocusableElement = function getNextFocusableElement(refs, currentFocusedIdx) {
21
- while (currentFocusedIdx + 1 < refs.length) {
22
- var element = refs[++currentFocusedIdx].current;
23
- var isValid = !!element && !element.hasAttribute('disabled');
24
- if (isValid) {
25
- return element;
21
+ if ((0, _platformFeatureFlags.fg)('dropdown-menu-disabled-navigation-fix')) {
22
+ for (var i = 0; i < refs.length - 1; i++) {
23
+ if (currentFocusedIdx + 1 === refs.length) {
24
+ currentFocusedIdx = 0;
25
+ } else {
26
+ currentFocusedIdx++;
27
+ }
28
+ var element = refs[currentFocusedIdx].current;
29
+ var isValid = !!element && !element.hasAttribute('disabled');
30
+ if (isValid) {
31
+ return element;
32
+ }
33
+ }
34
+ } else {
35
+ while (currentFocusedIdx + 1 < refs.length) {
36
+ var _element = refs[++currentFocusedIdx].current;
37
+ var _isValid = !!_element && !_element.hasAttribute('disabled');
38
+ if (_isValid) {
39
+ return _element;
40
+ }
26
41
  }
27
42
  }
28
43
  };
@@ -34,11 +49,26 @@ var getNextFocusableElement = function getNextFocusableElement(refs, currentFocu
34
49
  * return undefined.
35
50
  */
36
51
  var getPrevFocusableElement = function getPrevFocusableElement(refs, currentFocusedIdx) {
37
- while (currentFocusedIdx > 0) {
38
- var element = refs[--currentFocusedIdx].current;
39
- var isValid = !!element && !element.hasAttribute('disabled');
40
- if (isValid) {
41
- return element;
52
+ if ((0, _platformFeatureFlags.fg)('dropdown-menu-disabled-navigation-fix')) {
53
+ for (var i = 0; i < refs.length - 1; i++) {
54
+ if (currentFocusedIdx === 0) {
55
+ currentFocusedIdx = refs.length - 1;
56
+ } else {
57
+ currentFocusedIdx--;
58
+ }
59
+ var element = refs[currentFocusedIdx].current;
60
+ var isValid = !!element && !element.hasAttribute('disabled');
61
+ if (isValid) {
62
+ return element;
63
+ }
64
+ }
65
+ } else {
66
+ while (currentFocusedIdx > 0) {
67
+ var _element2 = refs[--currentFocusedIdx].current;
68
+ var _isValid2 = !!_element2 && !_element2.hasAttribute('disabled');
69
+ if (_isValid2) {
70
+ return _element2;
71
+ }
42
72
  }
43
73
  }
44
74
  };
@@ -80,9 +110,16 @@ function handleFocus(refs, isLayerDisabled, onClose) {
80
110
  case 'next':
81
111
  // Always cancelling the event to prevent scrolling
82
112
  e.preventDefault();
83
- if (currentFocusedIdx < currentRefs.length - 1) {
113
+ if ((0, _platformFeatureFlags.fg)('dropdown-menu-disabled-navigation-fix')) {
84
114
  var _nextFocusableElement = getNextFocusableElement(currentRefs, currentFocusedIdx);
85
115
  _nextFocusableElement === null || _nextFocusableElement === void 0 || _nextFocusableElement.focus();
116
+ break;
117
+ }
118
+
119
+ // Remove on FG cleanup dropdown-menu-disabled-navigation-fix
120
+ if (currentFocusedIdx < currentRefs.length - 1) {
121
+ var _nextFocusableElement2 = getNextFocusableElement(currentRefs, currentFocusedIdx);
122
+ _nextFocusableElement2 === null || _nextFocusableElement2 === void 0 || _nextFocusableElement2.focus();
86
123
  } else {
87
124
  var firstFocusableElement = getNextFocusableElement(currentRefs, -1);
88
125
  firstFocusableElement === null || firstFocusableElement === void 0 || firstFocusableElement.focus();
@@ -91,9 +128,16 @@ function handleFocus(refs, isLayerDisabled, onClose) {
91
128
  case 'prev':
92
129
  // Always cancelling the event to prevent scrolling
93
130
  e.preventDefault();
94
- if (currentFocusedIdx > 0) {
131
+ if ((0, _platformFeatureFlags.fg)('dropdown-menu-disabled-navigation-fix')) {
95
132
  var _prevFocusableElement = getPrevFocusableElement(currentRefs, currentFocusedIdx);
96
133
  _prevFocusableElement === null || _prevFocusableElement === void 0 || _prevFocusableElement.focus();
134
+ break;
135
+ }
136
+
137
+ // Remove on FG cleanup dropdown-menu-disabled-navigation-fix
138
+ if (currentFocusedIdx > 0) {
139
+ var _prevFocusableElement2 = getPrevFocusableElement(currentRefs, currentFocusedIdx);
140
+ _prevFocusableElement2 === null || _prevFocusableElement2 === void 0 || _prevFocusableElement2.focus();
97
141
  } else {
98
142
  var lastFocusableElement = getPrevFocusableElement(currentRefs, currentRefs.length);
99
143
  lastFocusableElement === null || lastFocusableElement === void 0 || lastFocusableElement.focus();
@@ -15,13 +15,30 @@ const actionMap = {
15
15
  * return undefined.
16
16
  */
17
17
  const getNextFocusableElement = (refs, currentFocusedIdx) => {
18
- while (currentFocusedIdx + 1 < refs.length) {
19
- const {
20
- current: element
21
- } = refs[++currentFocusedIdx];
22
- const isValid = !!element && !element.hasAttribute('disabled');
23
- if (isValid) {
24
- return element;
18
+ if (fg('dropdown-menu-disabled-navigation-fix')) {
19
+ for (let i = 0; i < refs.length - 1; i++) {
20
+ if (currentFocusedIdx + 1 === refs.length) {
21
+ currentFocusedIdx = 0;
22
+ } else {
23
+ currentFocusedIdx++;
24
+ }
25
+ const {
26
+ current: element
27
+ } = refs[currentFocusedIdx];
28
+ const isValid = !!element && !element.hasAttribute('disabled');
29
+ if (isValid) {
30
+ return element;
31
+ }
32
+ }
33
+ } else {
34
+ while (currentFocusedIdx + 1 < refs.length) {
35
+ const {
36
+ current: element
37
+ } = refs[++currentFocusedIdx];
38
+ const isValid = !!element && !element.hasAttribute('disabled');
39
+ if (isValid) {
40
+ return element;
41
+ }
25
42
  }
26
43
  }
27
44
  };
@@ -33,13 +50,30 @@ const getNextFocusableElement = (refs, currentFocusedIdx) => {
33
50
  * return undefined.
34
51
  */
35
52
  const getPrevFocusableElement = (refs, currentFocusedIdx) => {
36
- while (currentFocusedIdx > 0) {
37
- const {
38
- current: element
39
- } = refs[--currentFocusedIdx];
40
- const isValid = !!element && !element.hasAttribute('disabled');
41
- if (isValid) {
42
- return element;
53
+ if (fg('dropdown-menu-disabled-navigation-fix')) {
54
+ for (let i = 0; i < refs.length - 1; i++) {
55
+ if (currentFocusedIdx === 0) {
56
+ currentFocusedIdx = refs.length - 1;
57
+ } else {
58
+ currentFocusedIdx--;
59
+ }
60
+ const {
61
+ current: element
62
+ } = refs[currentFocusedIdx];
63
+ const isValid = !!element && !element.hasAttribute('disabled');
64
+ if (isValid) {
65
+ return element;
66
+ }
67
+ }
68
+ } else {
69
+ while (currentFocusedIdx > 0) {
70
+ const {
71
+ current: element
72
+ } = refs[--currentFocusedIdx];
73
+ const isValid = !!element && !element.hasAttribute('disabled');
74
+ if (isValid) {
75
+ return element;
76
+ }
43
77
  }
44
78
  }
45
79
  };
@@ -82,6 +116,13 @@ export default function handleFocus(refs, isLayerDisabled, onClose) {
82
116
  case 'next':
83
117
  // Always cancelling the event to prevent scrolling
84
118
  e.preventDefault();
119
+ if (fg('dropdown-menu-disabled-navigation-fix')) {
120
+ const nextFocusableElement = getNextFocusableElement(currentRefs, currentFocusedIdx);
121
+ nextFocusableElement === null || nextFocusableElement === void 0 ? void 0 : nextFocusableElement.focus();
122
+ break;
123
+ }
124
+
125
+ // Remove on FG cleanup dropdown-menu-disabled-navigation-fix
85
126
  if (currentFocusedIdx < currentRefs.length - 1) {
86
127
  const nextFocusableElement = getNextFocusableElement(currentRefs, currentFocusedIdx);
87
128
  nextFocusableElement === null || nextFocusableElement === void 0 ? void 0 : nextFocusableElement.focus();
@@ -93,6 +134,13 @@ export default function handleFocus(refs, isLayerDisabled, onClose) {
93
134
  case 'prev':
94
135
  // Always cancelling the event to prevent scrolling
95
136
  e.preventDefault();
137
+ if (fg('dropdown-menu-disabled-navigation-fix')) {
138
+ const prevFocusableElement = getPrevFocusableElement(currentRefs, currentFocusedIdx);
139
+ prevFocusableElement === null || prevFocusableElement === void 0 ? void 0 : prevFocusableElement.focus();
140
+ break;
141
+ }
142
+
143
+ // Remove on FG cleanup dropdown-menu-disabled-navigation-fix
96
144
  if (currentFocusedIdx > 0) {
97
145
  const prevFocusableElement = getPrevFocusableElement(currentRefs, currentFocusedIdx);
98
146
  prevFocusableElement === null || prevFocusableElement === void 0 ? void 0 : prevFocusableElement.focus();
@@ -11,11 +11,26 @@ var actionMap = _defineProperty(_defineProperty(_defineProperty(_defineProperty(
11
11
  * return undefined.
12
12
  */
13
13
  var getNextFocusableElement = function getNextFocusableElement(refs, currentFocusedIdx) {
14
- while (currentFocusedIdx + 1 < refs.length) {
15
- var element = refs[++currentFocusedIdx].current;
16
- var isValid = !!element && !element.hasAttribute('disabled');
17
- if (isValid) {
18
- return element;
14
+ if (fg('dropdown-menu-disabled-navigation-fix')) {
15
+ for (var i = 0; i < refs.length - 1; i++) {
16
+ if (currentFocusedIdx + 1 === refs.length) {
17
+ currentFocusedIdx = 0;
18
+ } else {
19
+ currentFocusedIdx++;
20
+ }
21
+ var element = refs[currentFocusedIdx].current;
22
+ var isValid = !!element && !element.hasAttribute('disabled');
23
+ if (isValid) {
24
+ return element;
25
+ }
26
+ }
27
+ } else {
28
+ while (currentFocusedIdx + 1 < refs.length) {
29
+ var _element = refs[++currentFocusedIdx].current;
30
+ var _isValid = !!_element && !_element.hasAttribute('disabled');
31
+ if (_isValid) {
32
+ return _element;
33
+ }
19
34
  }
20
35
  }
21
36
  };
@@ -27,11 +42,26 @@ var getNextFocusableElement = function getNextFocusableElement(refs, currentFocu
27
42
  * return undefined.
28
43
  */
29
44
  var getPrevFocusableElement = function getPrevFocusableElement(refs, currentFocusedIdx) {
30
- while (currentFocusedIdx > 0) {
31
- var element = refs[--currentFocusedIdx].current;
32
- var isValid = !!element && !element.hasAttribute('disabled');
33
- if (isValid) {
34
- return element;
45
+ if (fg('dropdown-menu-disabled-navigation-fix')) {
46
+ for (var i = 0; i < refs.length - 1; i++) {
47
+ if (currentFocusedIdx === 0) {
48
+ currentFocusedIdx = refs.length - 1;
49
+ } else {
50
+ currentFocusedIdx--;
51
+ }
52
+ var element = refs[currentFocusedIdx].current;
53
+ var isValid = !!element && !element.hasAttribute('disabled');
54
+ if (isValid) {
55
+ return element;
56
+ }
57
+ }
58
+ } else {
59
+ while (currentFocusedIdx > 0) {
60
+ var _element2 = refs[--currentFocusedIdx].current;
61
+ var _isValid2 = !!_element2 && !_element2.hasAttribute('disabled');
62
+ if (_isValid2) {
63
+ return _element2;
64
+ }
35
65
  }
36
66
  }
37
67
  };
@@ -73,9 +103,16 @@ export default function handleFocus(refs, isLayerDisabled, onClose) {
73
103
  case 'next':
74
104
  // Always cancelling the event to prevent scrolling
75
105
  e.preventDefault();
76
- if (currentFocusedIdx < currentRefs.length - 1) {
106
+ if (fg('dropdown-menu-disabled-navigation-fix')) {
77
107
  var _nextFocusableElement = getNextFocusableElement(currentRefs, currentFocusedIdx);
78
108
  _nextFocusableElement === null || _nextFocusableElement === void 0 || _nextFocusableElement.focus();
109
+ break;
110
+ }
111
+
112
+ // Remove on FG cleanup dropdown-menu-disabled-navigation-fix
113
+ if (currentFocusedIdx < currentRefs.length - 1) {
114
+ var _nextFocusableElement2 = getNextFocusableElement(currentRefs, currentFocusedIdx);
115
+ _nextFocusableElement2 === null || _nextFocusableElement2 === void 0 || _nextFocusableElement2.focus();
79
116
  } else {
80
117
  var firstFocusableElement = getNextFocusableElement(currentRefs, -1);
81
118
  firstFocusableElement === null || firstFocusableElement === void 0 || firstFocusableElement.focus();
@@ -84,9 +121,16 @@ export default function handleFocus(refs, isLayerDisabled, onClose) {
84
121
  case 'prev':
85
122
  // Always cancelling the event to prevent scrolling
86
123
  e.preventDefault();
87
- if (currentFocusedIdx > 0) {
124
+ if (fg('dropdown-menu-disabled-navigation-fix')) {
88
125
  var _prevFocusableElement = getPrevFocusableElement(currentRefs, currentFocusedIdx);
89
126
  _prevFocusableElement === null || _prevFocusableElement === void 0 || _prevFocusableElement.focus();
127
+ break;
128
+ }
129
+
130
+ // Remove on FG cleanup dropdown-menu-disabled-navigation-fix
131
+ if (currentFocusedIdx > 0) {
132
+ var _prevFocusableElement2 = getPrevFocusableElement(currentRefs, currentFocusedIdx);
133
+ _prevFocusableElement2 === null || _prevFocusableElement2 === void 0 || _prevFocusableElement2.focus();
90
134
  } else {
91
135
  var lastFocusableElement = getPrevFocusableElement(currentRefs, currentRefs.length);
92
136
  lastFocusableElement === null || lastFocusableElement === void 0 || lastFocusableElement.focus();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "13.0.1",
3
+ "version": "13.0.3",
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/"
@@ -46,20 +46,20 @@
46
46
  "react-dom": "^18.2.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@af/accessibility-testing": "*",
50
- "@af/integration-testing": "*",
51
- "@af/visual-regression": "*",
49
+ "@af/accessibility-testing": "^2.0.0",
50
+ "@af/integration-testing": "^0.5.0",
51
+ "@af/visual-regression": "^1.3.0",
52
52
  "@atlaskit/app-provider": "^2.0.0",
53
53
  "@atlaskit/atlassian-navigation": "^5.0.0",
54
54
  "@atlaskit/avatar": "^24.0.0",
55
55
  "@atlaskit/checkbox": "^17.0.0",
56
- "@atlaskit/docs": "*",
56
+ "@atlaskit/docs": "^10.0.0",
57
57
  "@atlaskit/form": "^12.0.0",
58
58
  "@atlaskit/heading": "^5.1.0",
59
- "@atlaskit/link": "*",
59
+ "@atlaskit/link": "^3.0.0",
60
60
  "@atlaskit/lozenge": "^12.2.0",
61
61
  "@atlaskit/modal-dialog": "^13.0.0",
62
- "@atlaskit/section-message": "*",
62
+ "@atlaskit/section-message": "^8.1.0",
63
63
  "@atlaskit/textfield": "^8.0.0",
64
64
  "@atlaskit/toggle": "^15.0.0",
65
65
  "@testing-library/react": "^13.4.0",
@@ -101,6 +101,9 @@
101
101
  "fix-dropdown-close-outside-iframe": {
102
102
  "type": "boolean",
103
103
  "referenceOnly": true
104
+ },
105
+ "dropdown-menu-disabled-navigation-fix": {
106
+ "type": "boolean"
104
107
  }
105
108
  },
106
109
  "techstack": {