@atlaskit/react-select 2.6.6 → 2.7.0
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 +9 -0
- package/dist/cjs/accessibility/index.js +3 -49
- package/dist/cjs/compiled/components/live-region.js +8 -72
- package/dist/cjs/emotion/components/live-region.js +10 -76
- package/dist/cjs/select.js +141 -99
- package/dist/es2019/accessibility/index.js +3 -50
- package/dist/es2019/compiled/components/live-region.js +7 -71
- package/dist/es2019/emotion/components/live-region.js +7 -72
- package/dist/es2019/select.js +117 -82
- package/dist/esm/accessibility/index.js +3 -49
- package/dist/esm/compiled/components/live-region.js +9 -73
- package/dist/esm/emotion/components/live-region.js +9 -74
- package/dist/esm/select.js +139 -98
- package/dist/types/accessibility/index.d.ts +0 -2
- package/dist/types/compiled/components/live-region.d.ts +0 -2
- package/dist/types/emotion/components/live-region.d.ts +0 -2
- package/dist/types/select.d.ts +5 -6
- package/dist/types-ts4.5/accessibility/index.d.ts +0 -2
- package/dist/types-ts4.5/compiled/components/live-region.d.ts +0 -2
- package/dist/types-ts4.5/emotion/components/live-region.d.ts +0 -2
- package/dist/types-ts4.5/select.d.ts +5 -6
- package/package.json +1 -4
package/dist/cjs/select.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var
|
|
4
|
+
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.defaultProps = exports.default = void 0;
|
|
9
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
10
|
var _readOnlyError2 = _interopRequireDefault(require("@babel/runtime/helpers/readOnlyError"));
|
|
11
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
12
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
13
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
14
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
@@ -27,15 +28,12 @@ var _menu = require("./components/menu");
|
|
|
27
28
|
var _filters = require("./filters");
|
|
28
29
|
var _styles = require("./styles");
|
|
29
30
|
var _utils = require("./utils");
|
|
30
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" !=
|
|
31
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
31
32
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
32
33
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
33
34
|
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
34
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
35
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
35
36
|
var defaultProps = exports.defaultProps = {
|
|
36
|
-
// aria-live is by default with the live region so we don't need it
|
|
37
|
-
// eslint-disable-next-line @atlaskit/platform/no-module-level-eval
|
|
38
|
-
'aria-live': (0, _platformFeatureFlags.fg)('design_system_select-a11y-improvement') ? undefined : 'polite',
|
|
39
37
|
backspaceRemovesValue: true,
|
|
40
38
|
blurInputOnSelect: (0, _utils.isTouchCapable)(),
|
|
41
39
|
captureMenuScroll: !(0, _utils.isTouchCapable)(),
|
|
@@ -259,7 +257,6 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
259
257
|
(0, _defineProperty2.default)(_this, "initialTouchY", 0);
|
|
260
258
|
(0, _defineProperty2.default)(_this, "openAfterFocus", false);
|
|
261
259
|
(0, _defineProperty2.default)(_this, "scrollToFocusedOptionOnUpdate", false);
|
|
262
|
-
(0, _defineProperty2.default)(_this, "isVoiceOver", (0, _platformFeatureFlags.fg)('design_system_select-a11y-improvement') && (0, _deviceCheck.isAppleDevice)());
|
|
263
260
|
// Refs
|
|
264
261
|
// ------------------------------
|
|
265
262
|
(0, _defineProperty2.default)(_this, "controlRef", null);
|
|
@@ -965,17 +962,70 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
965
962
|
openAtIndex = selectedIndex;
|
|
966
963
|
}
|
|
967
964
|
}
|
|
965
|
+
var focusedOption = focusableOptions[openAtIndex];
|
|
968
966
|
|
|
969
967
|
// only scroll if the menu isn't already open
|
|
970
968
|
this.scrollToFocusedOptionOnUpdate = !(isFocused && this.menuListRef);
|
|
971
969
|
this.setState({
|
|
972
970
|
inputIsHiddenAfterUpdate: false,
|
|
973
971
|
focusedValue: null,
|
|
974
|
-
focusedOption:
|
|
975
|
-
focusedOptionId: this.getFocusedOptionId(
|
|
972
|
+
focusedOption: focusedOption,
|
|
973
|
+
focusedOptionId: this.getFocusedOptionId(focusedOption)
|
|
976
974
|
}, function () {
|
|
977
975
|
return _this2.onMenuOpen();
|
|
978
976
|
});
|
|
977
|
+
(0, _deviceCheck.isSafari)() && focusedOption && this.updateInputLabel(this.calculateInputLabel(focusedOption, openAtIndex));
|
|
978
|
+
}
|
|
979
|
+
}, {
|
|
980
|
+
key: "updateInputLabel",
|
|
981
|
+
value: function updateInputLabel(inputLabel) {
|
|
982
|
+
var _this3 = this;
|
|
983
|
+
if (inputLabel) {
|
|
984
|
+
var _this$inputRef;
|
|
985
|
+
(_this$inputRef = this.inputRef) === null || _this$inputRef === void 0 || _this$inputRef.setAttribute('aria-label', inputLabel);
|
|
986
|
+
setTimeout(function () {
|
|
987
|
+
var normalizedLabel = _this3.props['aria-label'] || _this3.props.label;
|
|
988
|
+
if (normalizedLabel) {
|
|
989
|
+
var _this3$inputRef;
|
|
990
|
+
(_this3$inputRef = _this3.inputRef) === null || _this3$inputRef === void 0 || _this3$inputRef.setAttribute('aria-label', normalizedLabel);
|
|
991
|
+
} else {
|
|
992
|
+
var _this3$inputRef2;
|
|
993
|
+
(_this3$inputRef2 = _this3.inputRef) === null || _this3$inputRef2 === void 0 || _this3$inputRef2.removeAttribute('aria-label');
|
|
994
|
+
}
|
|
995
|
+
}, 500);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}, {
|
|
999
|
+
key: "calculateInputLabel",
|
|
1000
|
+
value: function calculateInputLabel(focusedOption, optionIndex) {
|
|
1001
|
+
var _this4 = this;
|
|
1002
|
+
var options = this.props.options;
|
|
1003
|
+
var isOptionsGrouped = options === null || options === void 0 ? void 0 : options.every(function (obj) {
|
|
1004
|
+
return (0, _typeof2.default)(obj) === 'object' && obj !== null && 'options' in obj;
|
|
1005
|
+
});
|
|
1006
|
+
var inputLabel = this.getOptionLabel(focusedOption);
|
|
1007
|
+
var isOptionFocused = function isOptionFocused(option) {
|
|
1008
|
+
return _this4.getOptionLabel(option) === inputLabel;
|
|
1009
|
+
};
|
|
1010
|
+
var groupData = options === null || options === void 0 ? void 0 : options.find(function (option) {
|
|
1011
|
+
var _groupCandidate$optio, _groupCandidate$optio2;
|
|
1012
|
+
var groupCandidate = option;
|
|
1013
|
+
return (_groupCandidate$optio = (_groupCandidate$optio2 = groupCandidate.options) === null || _groupCandidate$optio2 === void 0 ? void 0 : _groupCandidate$optio2.some(isOptionFocused)) !== null && _groupCandidate$optio !== void 0 ? _groupCandidate$optio : false;
|
|
1014
|
+
});
|
|
1015
|
+
if (isOptionsGrouped) {
|
|
1016
|
+
var _groupData$options$fi;
|
|
1017
|
+
var groupOptionIndex = (_groupData$options$fi = groupData === null || groupData === void 0 ? void 0 : groupData.options.findIndex(isOptionFocused)) !== null && _groupData$options$fi !== void 0 ? _groupData$options$fi : 0;
|
|
1018
|
+
var totalLength = options === null || options === void 0 ? void 0 : options.reduce(function (acc, currentGroup) {
|
|
1019
|
+
var _group$options;
|
|
1020
|
+
var group = currentGroup;
|
|
1021
|
+
acc += group === null || group === void 0 || (_group$options = group.options) === null || _group$options === void 0 ? void 0 : _group$options.length;
|
|
1022
|
+
return acc;
|
|
1023
|
+
}, 0);
|
|
1024
|
+
inputLabel = "".concat(inputLabel, ", ").concat(groupData === null || groupData === void 0 ? void 0 : groupData.label, " (").concat(groupOptionIndex + 1, " of ").concat(totalLength, ")");
|
|
1025
|
+
} else {
|
|
1026
|
+
inputLabel = "".concat(inputLabel, " (").concat(optionIndex + 1, " of ").concat(options === null || options === void 0 ? void 0 : options.length, ")");
|
|
1027
|
+
}
|
|
1028
|
+
return inputLabel;
|
|
979
1029
|
}
|
|
980
1030
|
}, {
|
|
981
1031
|
key: "focusValue",
|
|
@@ -1158,24 +1208,36 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1158
1208
|
}
|
|
1159
1209
|
}, {
|
|
1160
1210
|
key: "calculateDescription",
|
|
1161
|
-
value: function calculateDescription(
|
|
1162
|
-
var descriptionProp = this.props['aria-describedby'] || this.props
|
|
1211
|
+
value: function calculateDescription() {
|
|
1212
|
+
var descriptionProp = this.props['aria-describedby'] || this.props.descriptionId;
|
|
1163
1213
|
var isMulti = this.props.isMulti;
|
|
1164
|
-
var
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1214
|
+
var hasValue = this.state.selectValue.length > 0;
|
|
1215
|
+
|
|
1216
|
+
// Determine base description based on selection state
|
|
1217
|
+
var baseDescriptionId = hasValue ? isMulti ? '' : this.getElementId('single-value') : this.getElementId('placeholder');
|
|
1218
|
+
|
|
1219
|
+
// Fast path for single select with no description prop
|
|
1220
|
+
if (!isMulti && !descriptionProp) {
|
|
1221
|
+
return {
|
|
1222
|
+
'aria-describedby': baseDescriptionId
|
|
1223
|
+
};
|
|
1168
1224
|
}
|
|
1225
|
+
|
|
1226
|
+
// Build the describedby string efficiently
|
|
1227
|
+
var describedBy = baseDescriptionId;
|
|
1228
|
+
// Add description prop if it exists
|
|
1229
|
+
if (descriptionProp) {
|
|
1230
|
+
describedBy = describedBy ? "".concat(descriptionProp, " ").concat(describedBy) : descriptionProp;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
// For multi-select, always add multi-message ID
|
|
1169
1234
|
if (isMulti) {
|
|
1170
1235
|
var multiMessage = this.getElementId('multi-message');
|
|
1171
|
-
|
|
1172
|
-
'aria-describedby': descriptionProp ? [descriptionProp, defaultDescription, multiMessage].join(' ') : [defaultDescription, multiMessage].join(' ')
|
|
1173
|
-
};
|
|
1174
|
-
} else {
|
|
1175
|
-
return {
|
|
1176
|
-
'aria-describedby': descriptionProp ? [descriptionProp, defaultDescription].join(' ') : defaultDescription
|
|
1177
|
-
};
|
|
1236
|
+
describedBy = describedBy ? "".concat(describedBy, " ").concat(multiMessage) : multiMessage;
|
|
1178
1237
|
}
|
|
1238
|
+
return {
|
|
1239
|
+
'aria-describedby': describedBy
|
|
1240
|
+
};
|
|
1179
1241
|
}
|
|
1180
1242
|
}, {
|
|
1181
1243
|
key: "startListeningComposition",
|
|
@@ -1239,7 +1301,6 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1239
1301
|
// ==============================
|
|
1240
1302
|
function renderInput() {
|
|
1241
1303
|
var _this$props8 = this.props,
|
|
1242
|
-
descriptionId = _this$props8.descriptionId,
|
|
1243
1304
|
form = _this$props8.form,
|
|
1244
1305
|
inputId = _this$props8.inputId,
|
|
1245
1306
|
inputValue = _this$props8.inputValue,
|
|
@@ -1256,9 +1317,7 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1256
1317
|
testId = _this$props8.testId;
|
|
1257
1318
|
var _this$getComponents = this.getComponents(),
|
|
1258
1319
|
Input = _this$getComponents.Input;
|
|
1259
|
-
var
|
|
1260
|
-
inputIsHidden = _this$state4.inputIsHidden,
|
|
1261
|
-
ariaSelection = _this$state4.ariaSelection;
|
|
1320
|
+
var inputIsHidden = this.state.inputIsHidden;
|
|
1262
1321
|
var commonProps = this.commonProps;
|
|
1263
1322
|
var id = inputId || this.getElementId('input');
|
|
1264
1323
|
|
|
@@ -1269,7 +1328,6 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1269
1328
|
'aria-expanded': menuIsOpen,
|
|
1270
1329
|
// TODO: aria-haspopup is implied as listbox with role="combobox" and was deprecated for aria 1.2, we still might need to keep it for back compat
|
|
1271
1330
|
'aria-haspopup': this.props['UNSAFE_is_experimental_generic'] ? 'dialog' : 'listbox',
|
|
1272
|
-
'aria-describedby': this.props['aria-describedby'] || descriptionId,
|
|
1273
1331
|
'aria-invalid': this.props['aria-invalid'] || isInvalid,
|
|
1274
1332
|
'aria-label': this.props['aria-label'] || label,
|
|
1275
1333
|
'aria-labelledby': this.props['aria-labelledby'] || labelId,
|
|
@@ -1280,7 +1338,7 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1280
1338
|
'aria-controls': this.getElementId('listbox')
|
|
1281
1339
|
}), !isSearchable && {
|
|
1282
1340
|
'aria-readonly': true
|
|
1283
|
-
}), this.calculateDescription(
|
|
1341
|
+
}), this.calculateDescription());
|
|
1284
1342
|
if (!isSearchable) {
|
|
1285
1343
|
// use a dummy input to maintain focus/blur functionality
|
|
1286
1344
|
return /*#__PURE__*/_react.default.createElement(_internal.DummyInput, (0, _extends2.default)({
|
|
@@ -1319,7 +1377,7 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1319
1377
|
}, {
|
|
1320
1378
|
key: "renderPlaceholderOrValue",
|
|
1321
1379
|
value: function renderPlaceholderOrValue() {
|
|
1322
|
-
var
|
|
1380
|
+
var _this5 = this;
|
|
1323
1381
|
var _this$getComponents2 = this.getComponents(),
|
|
1324
1382
|
MultiValue = _this$getComponents2.MultiValue,
|
|
1325
1383
|
MultiValueContainer = _this$getComponents2.MultiValueContainer,
|
|
@@ -1335,10 +1393,10 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1335
1393
|
inputValue = _this$props9.inputValue,
|
|
1336
1394
|
placeholder = _this$props9.placeholder,
|
|
1337
1395
|
testId = _this$props9.testId;
|
|
1338
|
-
var _this$
|
|
1339
|
-
selectValue = _this$
|
|
1340
|
-
focusedValue = _this$
|
|
1341
|
-
isFocused = _this$
|
|
1396
|
+
var _this$state4 = this.state,
|
|
1397
|
+
selectValue = _this$state4.selectValue,
|
|
1398
|
+
focusedValue = _this$state4.focusedValue,
|
|
1399
|
+
isFocused = _this$state4.isFocused;
|
|
1342
1400
|
if (!this.hasValue() || !controlShouldRenderValue) {
|
|
1343
1401
|
return inputValue ? null : /*#__PURE__*/_react.default.createElement(Placeholder, (0, _extends2.default)({}, commonProps, {
|
|
1344
1402
|
key: "placeholder",
|
|
@@ -1354,7 +1412,7 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1354
1412
|
if (isMulti) {
|
|
1355
1413
|
return selectValue.map(function (opt, index) {
|
|
1356
1414
|
var isOptionFocused = opt === focusedValue;
|
|
1357
|
-
var key = "".concat(
|
|
1415
|
+
var key = "".concat(_this5.getOptionLabel(opt), "-").concat(_this5.getOptionValue(opt));
|
|
1358
1416
|
return /*#__PURE__*/_react.default.createElement(MultiValue, (0, _extends2.default)({}, commonProps, {
|
|
1359
1417
|
components: {
|
|
1360
1418
|
Container: MultiValueContainer,
|
|
@@ -1367,10 +1425,10 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1367
1425
|
index: index,
|
|
1368
1426
|
removeProps: _objectSpread(_objectSpread({
|
|
1369
1427
|
onClick: function onClick() {
|
|
1370
|
-
return
|
|
1428
|
+
return _this5.removeValue(opt);
|
|
1371
1429
|
},
|
|
1372
1430
|
onTouchEnd: function onTouchEnd() {
|
|
1373
|
-
return
|
|
1431
|
+
return _this5.removeValue(opt);
|
|
1374
1432
|
},
|
|
1375
1433
|
onMouseDown: function onMouseDown(e) {
|
|
1376
1434
|
e.preventDefault();
|
|
@@ -1378,15 +1436,15 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1378
1436
|
}, testId && {
|
|
1379
1437
|
'data-testid': "".concat(testId, "-select--multivalue-").concat(index, "-remove")
|
|
1380
1438
|
}), {}, {
|
|
1381
|
-
id: "".concat(
|
|
1439
|
+
id: "".concat(_this5.getElementId('selected-value'), "-").concat(index, "-remove")
|
|
1382
1440
|
}),
|
|
1383
1441
|
data: opt,
|
|
1384
1442
|
innerProps: _objectSpread(_objectSpread({}, testId && {
|
|
1385
1443
|
'data-testid': "".concat(testId, "-select--multivalue-").concat(index)
|
|
1386
1444
|
}), {}, {
|
|
1387
|
-
id: "".concat(
|
|
1445
|
+
id: "".concat(_this5.getElementId('selected-value'), "-").concat(index)
|
|
1388
1446
|
})
|
|
1389
|
-
}),
|
|
1447
|
+
}), _this5.formatOptionLabel(opt, 'value'));
|
|
1390
1448
|
});
|
|
1391
1449
|
}
|
|
1392
1450
|
if (inputValue) {
|
|
@@ -1395,7 +1453,10 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1395
1453
|
var singleValue = selectValue[0];
|
|
1396
1454
|
return /*#__PURE__*/_react.default.createElement(SingleValue, (0, _extends2.default)({}, commonProps, {
|
|
1397
1455
|
data: singleValue,
|
|
1398
|
-
isDisabled: isDisabled
|
|
1456
|
+
isDisabled: isDisabled,
|
|
1457
|
+
innerProps: {
|
|
1458
|
+
id: this.getElementId('single-value')
|
|
1459
|
+
}
|
|
1399
1460
|
}), this.formatOptionLabel(singleValue, 'value'));
|
|
1400
1461
|
}
|
|
1401
1462
|
}, {
|
|
@@ -1489,7 +1550,7 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1489
1550
|
}, {
|
|
1490
1551
|
key: "renderMenu",
|
|
1491
1552
|
value: function renderMenu() {
|
|
1492
|
-
var
|
|
1553
|
+
var _this6 = this;
|
|
1493
1554
|
var _this$getComponents6 = this.getComponents(),
|
|
1494
1555
|
Group = _this$getComponents6.Group,
|
|
1495
1556
|
GroupHeading = _this$getComponents6.GroupHeading,
|
|
@@ -1517,8 +1578,6 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1517
1578
|
noOptionsMessage = _this$props11.noOptionsMessage,
|
|
1518
1579
|
onMenuScrollToTop = _this$props11.onMenuScrollToTop,
|
|
1519
1580
|
onMenuScrollToBottom = _this$props11.onMenuScrollToBottom,
|
|
1520
|
-
labelId = _this$props11.labelId,
|
|
1521
|
-
label = _this$props11.label,
|
|
1522
1581
|
testId = _this$props11.testId;
|
|
1523
1582
|
if (!menuIsOpen) {
|
|
1524
1583
|
return null;
|
|
@@ -1534,22 +1593,22 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1534
1593
|
value = props.value;
|
|
1535
1594
|
var isFocused = focusedOption === data;
|
|
1536
1595
|
var onHover = isDisabled ? undefined : function () {
|
|
1537
|
-
return
|
|
1596
|
+
return _this6.onOptionHover(data);
|
|
1538
1597
|
};
|
|
1539
1598
|
var onSelect = isDisabled ? undefined : function () {
|
|
1540
|
-
return
|
|
1599
|
+
return _this6.selectOption(data);
|
|
1541
1600
|
};
|
|
1542
|
-
var optionId = "".concat(
|
|
1601
|
+
var optionId = "".concat(_this6.getElementId('option'), "-").concat(id);
|
|
1543
1602
|
var innerProps = _objectSpread({
|
|
1544
1603
|
id: optionId,
|
|
1545
1604
|
onClick: onSelect,
|
|
1546
1605
|
onMouseMove: onHover,
|
|
1547
1606
|
onMouseOver: onHover,
|
|
1548
|
-
role:
|
|
1549
|
-
'aria-selected':
|
|
1607
|
+
role: _this6.props['UNSAFE_is_experimental_generic'] ? 'listitem' : 'option',
|
|
1608
|
+
'aria-selected': _this6.props['UNSAFE_is_experimental_generic'] ? undefined : isSelected,
|
|
1550
1609
|
// We don't want aria-disabled if it's false. It's just noisy.
|
|
1551
|
-
'aria-disabled': !isDisabled
|
|
1552
|
-
'aria-describedby':
|
|
1610
|
+
'aria-disabled': !isDisabled ? undefined : isDisabled,
|
|
1611
|
+
'aria-describedby': headingId
|
|
1553
1612
|
}, testId && {
|
|
1554
1613
|
'data-testid': "".concat(testId, "-select--option-").concat(id)
|
|
1555
1614
|
});
|
|
@@ -1563,8 +1622,8 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1563
1622
|
type: type,
|
|
1564
1623
|
value: value,
|
|
1565
1624
|
isFocused: isFocused,
|
|
1566
|
-
innerRef: isFocused ?
|
|
1567
|
-
}),
|
|
1625
|
+
innerRef: isFocused ? _this6.getFocusedOptionRef : undefined
|
|
1626
|
+
}), _this6.formatOptionLabel(props.data, 'menu'));
|
|
1568
1627
|
};
|
|
1569
1628
|
var menuUI;
|
|
1570
1629
|
if (this.hasOptions()) {
|
|
@@ -1574,7 +1633,7 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1574
1633
|
var data = item.data,
|
|
1575
1634
|
options = item.options,
|
|
1576
1635
|
groupIndex = item.index;
|
|
1577
|
-
var groupId = "".concat(
|
|
1636
|
+
var groupId = "".concat(_this6.getElementId('group'), "-").concat(groupIndex);
|
|
1578
1637
|
var headingId = "".concat(groupId, "-heading");
|
|
1579
1638
|
return /*#__PURE__*/_react.default.createElement(Group, (0, _extends2.default)({}, commonProps, {
|
|
1580
1639
|
key: groupId,
|
|
@@ -1587,7 +1646,7 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1587
1646
|
}, testId && {
|
|
1588
1647
|
'data-testid': "".concat(testId, "-select--group-").concat(groupIndex, "-heading")
|
|
1589
1648
|
}),
|
|
1590
|
-
label:
|
|
1649
|
+
label: _this6.formatGroupLabel(item.data)
|
|
1591
1650
|
}), item.options.map(function (option) {
|
|
1592
1651
|
return render(option, "".concat(groupIndex, "-").concat(option.index), headingId);
|
|
1593
1652
|
}));
|
|
@@ -1623,26 +1682,6 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1623
1682
|
menuPosition: menuPosition,
|
|
1624
1683
|
menuShouldScrollIntoView: menuShouldScrollIntoView
|
|
1625
1684
|
};
|
|
1626
|
-
var calculateListboxLabel = function calculateListboxLabel() {
|
|
1627
|
-
var _this4$inputRef;
|
|
1628
|
-
// First in name calculation, overwrites aria-label
|
|
1629
|
-
if (labelId) {
|
|
1630
|
-
return {
|
|
1631
|
-
'aria-labelledby': labelId
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1634
|
-
// Second in name calcuation, overwrites everything else except aria-labelledby
|
|
1635
|
-
if (label) {
|
|
1636
|
-
return {
|
|
1637
|
-
'aria-label': label
|
|
1638
|
-
};
|
|
1639
|
-
}
|
|
1640
|
-
// Fallback if no label or labelId is provided, might catch label via <label for> otherwise
|
|
1641
|
-
// will most likely not have an accessible name
|
|
1642
|
-
return {
|
|
1643
|
-
'aria-labelledby': ((_this4$inputRef = _this4.inputRef) === null || _this4$inputRef === void 0 ? void 0 : _this4$inputRef.id) || _this4.getElementId('input')
|
|
1644
|
-
};
|
|
1645
|
-
};
|
|
1646
1685
|
var menuElement = /*#__PURE__*/_react.default.createElement(_menu.MenuPlacer, (0, _extends2.default)({}, commonProps, menuPlacementProps), function (_ref4) {
|
|
1647
1686
|
var ref = _ref4.ref,
|
|
1648
1687
|
_ref4$placerProps = _ref4.placerProps,
|
|
@@ -1651,9 +1690,9 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1651
1690
|
return /*#__PURE__*/_react.default.createElement(Menu, (0, _extends2.default)({}, commonProps, menuPlacementProps, {
|
|
1652
1691
|
innerRef: ref,
|
|
1653
1692
|
innerProps: _objectSpread({
|
|
1654
|
-
onMouseDown:
|
|
1655
|
-
onMouseMove:
|
|
1656
|
-
id:
|
|
1693
|
+
onMouseDown: _this6.onMenuMouseDown,
|
|
1694
|
+
onMouseMove: _this6.onMenuMouseMove,
|
|
1695
|
+
id: _this6.props.components.Menu ? _this6.getElementId('listbox') : undefined
|
|
1657
1696
|
}, testId && {
|
|
1658
1697
|
'data-testid': "".concat(testId, "-select--listbox-container")
|
|
1659
1698
|
}),
|
|
@@ -1665,23 +1704,28 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1665
1704
|
onBottomArrive: onMenuScrollToBottom,
|
|
1666
1705
|
lockEnabled: menuShouldBlockScroll
|
|
1667
1706
|
}, function (scrollTargetRef) {
|
|
1707
|
+
var _this6$inputRef, _this6$inputRef2;
|
|
1668
1708
|
return /*#__PURE__*/_react.default.createElement(MenuList, (0, _extends2.default)({}, commonProps, {
|
|
1669
1709
|
innerRef: function innerRef(instance) {
|
|
1670
|
-
|
|
1710
|
+
_this6.getMenuListRef(instance);
|
|
1671
1711
|
scrollTargetRef(instance);
|
|
1672
1712
|
},
|
|
1673
|
-
innerProps: _objectSpread(_objectSpread({
|
|
1674
|
-
role:
|
|
1675
|
-
|
|
1676
|
-
'aria-
|
|
1677
|
-
|
|
1713
|
+
innerProps: _objectSpread(_objectSpread(_objectSpread({
|
|
1714
|
+
role: _this6.props['UNSAFE_is_experimental_generic'] ? 'dialog' : 'listbox'
|
|
1715
|
+
}, _this6.props['UNSAFE_is_experimental_generic'] && {
|
|
1716
|
+
'aria-labelledby': ((_this6$inputRef = _this6.inputRef) === null || _this6$inputRef === void 0 ? void 0 : _this6$inputRef.id) || _this6.getElementId('input')
|
|
1717
|
+
}), {}, {
|
|
1718
|
+
'aria-multiselectable': !commonProps.isMulti || _this6.props['UNSAFE_is_experimental_generic'] ? undefined : commonProps.isMulti,
|
|
1719
|
+
id: _this6.getElementId('listbox')
|
|
1678
1720
|
}, testId && {
|
|
1679
1721
|
'data-testid': "".concat(testId, "-select--listbox")
|
|
1680
|
-
}), (0,
|
|
1722
|
+
}), (0, _deviceCheck.isSafari)() && !_this6.props['UNSAFE_is_experimental_generic'] && {
|
|
1723
|
+
'aria-describedby': ((_this6$inputRef2 = _this6.inputRef) === null || _this6$inputRef2 === void 0 ? void 0 : _this6$inputRef2.id) || _this6.getElementId('input')
|
|
1724
|
+
}),
|
|
1681
1725
|
isLoading: isLoading,
|
|
1682
1726
|
maxHeight: maxHeight,
|
|
1683
1727
|
focusedOption: focusedOption
|
|
1684
|
-
}),
|
|
1728
|
+
}), _this6.props['UNSAFE_is_experimental_generic'] ? /*#__PURE__*/_react.default.createElement("div", {
|
|
1685
1729
|
role: "list"
|
|
1686
1730
|
}, menuUI) : menuUI);
|
|
1687
1731
|
}));
|
|
@@ -1700,7 +1744,7 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1700
1744
|
}, {
|
|
1701
1745
|
key: "renderFormField",
|
|
1702
1746
|
value: function renderFormField() {
|
|
1703
|
-
var
|
|
1747
|
+
var _this7 = this;
|
|
1704
1748
|
var _this$props12 = this.props,
|
|
1705
1749
|
delimiter = _this$props12.delimiter,
|
|
1706
1750
|
isDisabled = _this$props12.isDisabled,
|
|
@@ -1720,7 +1764,7 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1720
1764
|
if (isMulti) {
|
|
1721
1765
|
if (delimiter) {
|
|
1722
1766
|
var value = selectValue.map(function (opt) {
|
|
1723
|
-
return
|
|
1767
|
+
return _this7.getOptionValue(opt);
|
|
1724
1768
|
}).join(delimiter);
|
|
1725
1769
|
return /*#__PURE__*/_react.default.createElement("input", {
|
|
1726
1770
|
name: name,
|
|
@@ -1733,7 +1777,7 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1733
1777
|
key: "i-".concat(i),
|
|
1734
1778
|
name: name,
|
|
1735
1779
|
type: "hidden",
|
|
1736
|
-
value:
|
|
1780
|
+
value: _this7.getOptionValue(opt)
|
|
1737
1781
|
});
|
|
1738
1782
|
}) : /*#__PURE__*/_react.default.createElement("input", {
|
|
1739
1783
|
name: name,
|
|
@@ -1755,34 +1799,32 @@ var Select = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
1755
1799
|
key: "renderLiveRegion",
|
|
1756
1800
|
value: function renderLiveRegion() {
|
|
1757
1801
|
var commonProps = this.commonProps;
|
|
1758
|
-
var _this$
|
|
1759
|
-
ariaSelection = _this$
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
isFocused = _this$state6.isFocused,
|
|
1763
|
-
selectValue = _this$state6.selectValue;
|
|
1802
|
+
var _this$state5 = this.state,
|
|
1803
|
+
ariaSelection = _this$state5.ariaSelection,
|
|
1804
|
+
isFocused = _this$state5.isFocused,
|
|
1805
|
+
selectValue = _this$state5.selectValue;
|
|
1764
1806
|
var focusableOptions = this.getFocusableOptions();
|
|
1765
1807
|
return /*#__PURE__*/_react.default.createElement(_liveRegion.default, (0, _extends2.default)({}, commonProps, {
|
|
1766
1808
|
id: this.getElementId('live-region'),
|
|
1767
1809
|
ariaSelection: ariaSelection,
|
|
1768
|
-
focusedOption: focusedOption,
|
|
1769
|
-
focusedValue: focusedValue,
|
|
1770
1810
|
isFocused: isFocused,
|
|
1771
1811
|
selectValue: selectValue,
|
|
1772
|
-
focusableOptions: focusableOptions
|
|
1773
|
-
isAppleDevice: this.isVoiceOver
|
|
1812
|
+
focusableOptions: focusableOptions
|
|
1774
1813
|
}));
|
|
1775
1814
|
}
|
|
1776
1815
|
}, {
|
|
1777
1816
|
key: "renderMultiselectMessage",
|
|
1778
1817
|
value: function renderMultiselectMessage() {
|
|
1818
|
+
// In the future, when we actually support touch devices, we'll need to update this to not be keyboard specific.
|
|
1819
|
+
// Also, since this is rendered onscreen, it should be transtlated automatically.
|
|
1820
|
+
var msg = ", multiple selections available, ".concat(this.state.selectValue.length ? 'Use left or right arrow keys to navigate selected items' : '');
|
|
1779
1821
|
return (
|
|
1780
1822
|
/*#__PURE__*/
|
|
1781
1823
|
// eslint-disable-next-line @atlaskit/design-system/use-primitives-text
|
|
1782
1824
|
_react.default.createElement("span", {
|
|
1783
1825
|
id: this.getElementId('multi-message'),
|
|
1784
1826
|
hidden: true
|
|
1785
|
-
},
|
|
1827
|
+
}, msg)
|
|
1786
1828
|
);
|
|
1787
1829
|
}
|
|
1788
1830
|
}, {
|
|
@@ -1,77 +1,30 @@
|
|
|
1
1
|
/* eslint-disable @atlaskit/platform/ensure-feature-flag-prefix */
|
|
2
2
|
|
|
3
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
3
|
export const defaultAriaLiveMessages = {
|
|
5
|
-
guidance: props => {
|
|
6
|
-
const {
|
|
7
|
-
isSearchable,
|
|
8
|
-
isMulti,
|
|
9
|
-
tabSelectsValue,
|
|
10
|
-
context,
|
|
11
|
-
isInitialFocus
|
|
12
|
-
} = props;
|
|
13
|
-
switch (context) {
|
|
14
|
-
case 'menu':
|
|
15
|
-
return `Use Up and Down to choose options, press Enter to select the currently focused option, press Escape to exit the menu${tabSelectsValue ? ', press Tab to select the option and exit the menu' : ''}.`;
|
|
16
|
-
case 'input':
|
|
17
|
-
return isInitialFocus ? `${props['aria-label'] || 'Select'} is focused ${isSearchable ? ',type to refine list' : ''}, press Down to open the menu, ${isMulti ? ' press left to focus selected values' : ''}` : '';
|
|
18
|
-
case 'value':
|
|
19
|
-
return 'Use left and right to toggle between focused values, press Backspace to remove the currently focused value';
|
|
20
|
-
default:
|
|
21
|
-
return '';
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
4
|
onChange: props => {
|
|
25
5
|
const {
|
|
26
6
|
action,
|
|
27
7
|
label = '',
|
|
28
|
-
labels,
|
|
29
8
|
isDisabled
|
|
30
9
|
} = props;
|
|
31
10
|
switch (action) {
|
|
32
11
|
case 'deselect-option':
|
|
33
12
|
case 'pop-value':
|
|
34
13
|
case 'remove-value':
|
|
35
|
-
return label.length
|
|
36
|
-
// TODO: this should be handled on backspace|delete if no value, but doing it here first
|
|
14
|
+
return label.length ? `option ${label}, deselected` : '';
|
|
37
15
|
case 'clear':
|
|
38
16
|
return 'All selected options have been cleared.';
|
|
39
|
-
case 'initial-input-focus':
|
|
40
|
-
return label.length && fg('design_system_select-a11y-improvement') || !fg('design_system_select-a11y-improvement') ? `option${labels.length > 1 ? 's' : ''} ${labels.join(',')}, selected.` : '';
|
|
41
17
|
case 'select-option':
|
|
42
|
-
return isDisabled ? `option ${label}
|
|
18
|
+
return label.length && !isDisabled ? `option ${label}, selected.` : '';
|
|
43
19
|
default:
|
|
44
20
|
return '';
|
|
45
21
|
}
|
|
46
22
|
},
|
|
47
|
-
onFocus: props => {
|
|
48
|
-
const {
|
|
49
|
-
context,
|
|
50
|
-
focused,
|
|
51
|
-
options,
|
|
52
|
-
label = '',
|
|
53
|
-
selectValue,
|
|
54
|
-
isDisabled,
|
|
55
|
-
isSelected
|
|
56
|
-
} = props;
|
|
57
|
-
const getArrayIndex = (arr, item) => arr && arr.length ? `(${arr.indexOf(item) + 1} of ${arr.length})` : '';
|
|
58
|
-
if (context === 'value' && selectValue) {
|
|
59
|
-
return `value ${label} focused, ${getArrayIndex(selectValue, focused)}.`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// No longer needed after fg('design_system_select-a11y-improvement') is cleaned up
|
|
63
|
-
if (context === 'menu' && !fg('design_system_select-a11y-improvement')) {
|
|
64
|
-
const disabled = isDisabled ? ' disabled' : '';
|
|
65
|
-
const status = `${isSelected ? ' selected' : ' not selected'}${disabled}`;
|
|
66
|
-
return `${label}${status}, ${getArrayIndex(options, focused)}, completion selected`;
|
|
67
|
-
}
|
|
68
|
-
return '';
|
|
69
|
-
},
|
|
70
23
|
onFilter: props => {
|
|
71
24
|
const {
|
|
72
25
|
inputValue,
|
|
73
26
|
resultsMessage
|
|
74
27
|
} = props;
|
|
75
|
-
return `${resultsMessage}
|
|
28
|
+
return inputValue ? `${resultsMessage} for search term ${inputValue}.` : '';
|
|
76
29
|
}
|
|
77
30
|
};
|