@bigbinary/neetoui 5.1.3 → 5.1.5

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/index.d.ts CHANGED
@@ -119,6 +119,7 @@ export interface AlertProps {
119
119
  message?: React.ReactNode;
120
120
  submitButtonLabel?: string;
121
121
  cancelButtonLabel?: string;
122
+ initialFocusElement?: "cancel" | "submit";
122
123
  }
123
124
 
124
125
  export type AvatarProps = {
@@ -324,7 +325,7 @@ export type SelectProps = {
324
325
  id?: string;
325
326
  loadOptions?: boolean;
326
327
  labelProps?: LabelProps;
327
- optionRemapping?: { label?: string, value?: string }
328
+ optionRemapping?: { label?: string; value?: string };
328
329
  [key: string]: any;
329
330
  };
330
331
 
package/index.js CHANGED
@@ -10208,7 +10208,7 @@ var UniqueArray = /*#__PURE__*/function () {
10208
10208
  var renderFocusOnFocusableElements = function renderFocusOnFocusableElements(ref) {
10209
10209
  var _ref$current, _ref$current2;
10210
10210
  var shouldFocusFirstFocusableElement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
10211
- var focusableElements = '[href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
10211
+ var focusableElements = 'button,[href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
10212
10212
  var firstFocusableElement = ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.querySelectorAll(focusableElements)[0];
10213
10213
  var focusableContent = ref === null || ref === void 0 ? void 0 : (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.querySelectorAll(focusableElements);
10214
10214
  var lastFocusableElement = focusableContent[(focusableContent === null || focusableContent === void 0 ? void 0 : focusableContent.length) - 1];
@@ -17326,6 +17326,10 @@ var SIZES$6 = {
17326
17326
  medium: "medium",
17327
17327
  large: "large"
17328
17328
  };
17329
+ var FOCUSABLE_ELEMENTS = {
17330
+ submit: "submit",
17331
+ cancel: "cancel"
17332
+ };
17329
17333
  var Alert = function Alert(_ref) {
17330
17334
  var _ref$size = _ref.size,
17331
17335
  size = _ref$size === void 0 ? SIZES$6.medium : _ref$size,
@@ -17354,8 +17358,14 @@ var Alert = function Alert(_ref) {
17354
17358
  _ref$submitButtonLabe = _ref.submitButtonLabel,
17355
17359
  submitButtonLabel = _ref$submitButtonLabe === void 0 ? "Continue" : _ref$submitButtonLabe,
17356
17360
  _ref$cancelButtonLabe = _ref.cancelButtonLabel,
17357
- cancelButtonLabel = _ref$cancelButtonLabe === void 0 ? "Cancel" : _ref$cancelButtonLabe;
17358
- return /*#__PURE__*/React__default.createElement(Modal, {
17361
+ cancelButtonLabel = _ref$cancelButtonLabe === void 0 ? "Cancel" : _ref$cancelButtonLabe,
17362
+ initialFocusRef = _ref.initialFocusRef,
17363
+ initialFocusElement = _ref.initialFocusElement;
17364
+ var submitButtonRef = useRef(null);
17365
+ var cancelButtonRef = useRef(null);
17366
+ var hasCustomFocusableElement = !!initialFocusRef || initialFocusElement;
17367
+ var initialFocusElementRef = initialFocusElement === FOCUSABLE_ELEMENTS.submit ? submitButtonRef : cancelButtonRef;
17368
+ return /*#__PURE__*/React__default.createElement(Modal, _extends$4({
17359
17369
  backdropClassName: backdropClassName,
17360
17370
  className: className,
17361
17371
  closeButton: closeButton,
@@ -17364,7 +17374,9 @@ var Alert = function Alert(_ref) {
17364
17374
  isOpen: isOpen,
17365
17375
  size: size,
17366
17376
  onClose: onClose
17367
- }, /*#__PURE__*/React__default.createElement(Modal.Header, null, /*#__PURE__*/React__default.createElement(Typography, {
17377
+ }, hasCustomFocusableElement && {
17378
+ initialFocusRef: initialFocusRef || initialFocusElementRef
17379
+ }), /*#__PURE__*/React__default.createElement(Modal.Header, null, /*#__PURE__*/React__default.createElement(Typography, {
17368
17380
  "data-cy": "alert-title",
17369
17381
  style: "h2"
17370
17382
  }, title)), /*#__PURE__*/React__default.createElement(Modal.Body, null, /*#__PURE__*/React__default.createElement(Typography, {
@@ -17378,11 +17390,13 @@ var Alert = function Alert(_ref) {
17378
17390
  disabled: !isOpen,
17379
17391
  label: submitButtonLabel,
17380
17392
  loading: isSubmitting,
17393
+ ref: submitButtonRef,
17381
17394
  style: "danger",
17382
17395
  onClick: onSubmit
17383
17396
  }), /*#__PURE__*/React__default.createElement(Button, {
17384
17397
  "data-cy": "alert-cancel-button",
17385
17398
  label: cancelButtonLabel,
17399
+ ref: cancelButtonRef,
17386
17400
  style: "text",
17387
17401
  onClick: onClose
17388
17402
  })));