@dnb/eufemia 9.17.1 → 9.17.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 CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to @dnb/eufemia will be documented in this file. See
4
4
  [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [9.17.2](https://github.com/dnbexperience/eufemia/compare/v9.17.1...v9.17.2) (2021-12-15)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix Modal DOM attribute cleanup during close when open_state is used ([28d14ae](https://github.com/dnbexperience/eufemia/commit/28d14aefa71d8af3a20126979ccd93d3b4c2930e))
12
+ * **InputMasked:** allow leading zero when custom mask is given ([d3ecada](https://github.com/dnbexperience/eufemia/commit/d3ecadae0ef86dc108840a833a2476cfd064dc9e))
13
+
6
14
  ## [9.17.1](https://github.com/dnbexperience/eufemia/compare/v9.17.0...v9.17.1) (2021-12-14)
7
15
 
8
16
 
@@ -313,26 +313,31 @@ var useEventMapping = function useEventMapping(_ref) {
313
313
  event: event
314
314
  }, 'on_before_input');
315
315
  },
316
+ onFocus: function onFocus(params) {
317
+ return callEvent(params, 'on_focus');
318
+ },
319
+ onBlur: function onBlur(params) {
320
+ return callEvent(params, 'on_blur');
321
+ },
316
322
  onMouseUp: function onMouseUp(event) {
317
323
  return callEvent({
318
324
  event: event
319
325
  }, 'on_mouse_up');
320
326
  },
321
- on_focus: function on_focus(params) {
322
- return callEvent(params, 'on_focus');
323
- },
324
- on_key_down: function on_key_down(params) {
327
+ onKeyDown: function onKeyDown(params) {
325
328
  return callEvent(params, 'on_key_down');
326
329
  },
327
- on_submit: function on_submit(params) {
330
+ onSubmit: function onSubmit(params) {
328
331
  return callEvent(params, 'on_submit');
329
332
  },
330
- on_blur: function on_blur(params) {
331
- return callEvent(params, 'on_blur');
332
- },
333
- on_change: function on_change(params) {
333
+ onChange: function onChange(params) {
334
334
  return callEvent(params, 'on_change');
335
- }
335
+ },
336
+ on_focus: undefined,
337
+ on_blur: undefined,
338
+ on_key_down: undefined,
339
+ on_submit: undefined,
340
+ on_change: undefined
336
341
  };
337
342
  };
338
343
 
@@ -345,11 +350,7 @@ var useCallEvent = function useCallEvent(_ref2) {
345
350
  props = _React$useContext8.props;
346
351
 
347
352
  var maskParams = useMaskParams();
348
-
349
- if (!maskParams) {
350
- return function () {};
351
- }
352
-
353
+ var isNumberMask = useNumberMask();
353
354
  var decimalSeparators = /[,.'·]/;
354
355
  var isUnidentified = false;
355
356
 
@@ -370,7 +371,7 @@ var useCallEvent = function useCallEvent(_ref2) {
370
371
  isUnidentified = false;
371
372
  }
372
373
 
373
- if (name === 'on_key_down' && !isUnidentified && !(maskParams !== null && maskParams !== void 0 && maskParams.allowLeadingZeroes) && (keyCode === '0' || value.replace(/[^\d]/g, '') === '' && decimalSeparators.test(keyCode))) {
374
+ if (name === 'on_key_down' && !isUnidentified && (isNumberMask && !(maskParams !== null && maskParams !== void 0 && maskParams.allowLeadingZeroes) || !isNumberMask && (maskParams === null || maskParams === void 0 ? void 0 : maskParams.allowLeadingZeroes) === false) && (keyCode === '0' || keyCode === 'numpad 0' || value.replace(/[^\d]/g, '') === '' && decimalSeparators.test(keyCode))) {
374
375
  var testValue = (value.slice(0, selStart) + '0' + value.slice(selStart + 1, value.length)).replace(/[^\d]/g, '');
375
376
 
376
377
  if (/^0/.test(testValue)) {
@@ -379,7 +380,7 @@ var useCallEvent = function useCallEvent(_ref2) {
379
380
  }
380
381
  }
381
382
 
382
- if (name === 'on_key_down' && !isUnidentified && maskParams !== null && maskParams !== void 0 && maskParams.decimalSymbol) {
383
+ if (name === 'on_key_down' && isNumberMask && !isUnidentified && maskParams !== null && maskParams !== void 0 && maskParams.decimalSymbol) {
383
384
  var hasDecimalSymbol = value.includes(maskParams.decimalSymbol);
384
385
  var allowedDecimals = maskParams.decimalLimit > 0 || maskParams.allowDecimal !== false;
385
386
 
@@ -242,6 +242,10 @@ export interface ModalProps extends React.HTMLProps<HTMLElement> {
242
242
  * Set a function to call the callback function, once the modal/drawer should close: `close_modal={(close) => close()}`
243
243
  */
244
244
  close_modal?: (...args: any[]) => any;
245
+
246
+ /**
247
+ * Provide a custom trigger component. Like `trigger={<Anchor href="/" />}`. It will set the focus on it when the modal/drawer gets closed.
248
+ */
245
249
  trigger?: ModalTrigger;
246
250
 
247
251
  /**
@@ -175,7 +175,6 @@ var Modal = function (_React$PureComponent) {
175
175
  hide: true
176
176
  });
177
177
 
178
- clearTimeout(_this._closeTimeout);
179
178
  _this._closeTimeout = setTimeout(doItNow, parseFloat(_this.props.animation_duration));
180
179
  } else {
181
180
  doItNow();
@@ -186,13 +185,14 @@ var Modal = function (_React$PureComponent) {
186
185
  var delay = parseFloat(_this.props.open_delay);
187
186
 
188
187
  if (delay > 0 && !(0, _componentHelper.isTrue)(_this.props.no_animation)) {
189
- clearTimeout(_this._openTimeout);
190
188
  _this._openTimeout = setTimeout(toggleNow, delay);
191
189
  } else {
192
190
  toggleNow();
193
191
  }
194
192
  };
195
193
 
194
+ clearTimeout(_this._closeTimeout);
195
+ clearTimeout(_this._openTimeout);
196
196
  var open_modal = _this.props.open_modal;
197
197
 
198
198
  if (typeof open_modal === 'function') {
@@ -238,13 +238,7 @@ var Modal = function (_React$PureComponent) {
238
238
  } catch (e) {}
239
239
  }
240
240
 
241
- var last = (0, _ModalContent.getListOfModalRoots)(-1);
242
-
243
- if (last) {
244
- _this.setActiveState(last._id);
245
- } else if ((0, _ModalContent.getListOfModalRoots)().length <= 1) {
246
- _this.setActiveState(false);
247
- }
241
+ _this.removeActiveState();
248
242
  }
249
243
  });
250
244
 
@@ -302,16 +296,15 @@ var Modal = function (_React$PureComponent) {
302
296
  }, {
303
297
  key: "componentWillUnmount",
304
298
  value: function componentWillUnmount() {
299
+ clearTimeout(this._openTimeout);
300
+ clearTimeout(this._closeTimeout);
301
+ this.removeActiveState(false);
302
+
305
303
  this._onUnmount.forEach(function (fn) {
306
304
  if (typeof fn === 'function') {
307
305
  fn();
308
306
  }
309
307
  });
310
-
311
- clearTimeout(this._openTimeout);
312
- clearTimeout(this._closeTimeout);
313
- clearTimeout(this._sideEffectsTimeout);
314
- clearTimeout(this._tryToOpenTimeout);
315
308
  }
316
309
  }, {
317
310
  key: "componentDidUpdate",
@@ -323,35 +316,48 @@ var Modal = function (_React$PureComponent) {
323
316
  }, {
324
317
  key: "openBasedOnStateUpdate",
325
318
  value: function openBasedOnStateUpdate() {
326
- var _this$state = this.state,
327
- hide = _this$state.hide,
328
- modalActive = _this$state.modalActive;
319
+ var hide = this.state.hide;
329
320
  var open_state = this.props.open_state;
330
321
 
331
322
  if (!this.activeElement && typeof document !== 'undefined') {
332
323
  this.activeElement = document.activeElement;
333
324
  }
334
325
 
335
- if (!hide && !modalActive && (open_state === 'opened' || open_state === true)) {
326
+ if (!hide && (open_state === 'opened' || open_state === true)) {
336
327
  this.toggleOpenClose(null, true);
337
- } else if (hide && modalActive && (open_state === 'closed' || open_state === false)) {
328
+ } else if (hide && (open_state === 'closed' || open_state === false)) {
338
329
  this.toggleOpenClose(null, false);
339
330
  }
340
331
  }
332
+ }, {
333
+ key: "removeActiveState",
334
+ value: function removeActiveState() {
335
+ var last = (0, _ModalContent.getListOfModalRoots)(-1);
336
+
337
+ if (last !== null && last !== void 0 && last._id && last._id !== this._id) {
338
+ return this.setActiveState(last._id);
339
+ }
340
+
341
+ try {
342
+ document.documentElement.removeAttribute('data-dnb-modal-active');
343
+ document.body.setAttribute('data-dnb-modal-active', 'false');
344
+ } catch (e) {
345
+ (0, _componentHelper.warn)('Modal: Error on remove "data-dnb-modal-active"', e);
346
+ }
347
+ }
341
348
  }, {
342
349
  key: "setActiveState",
343
350
  value: function setActiveState(modalId) {
351
+ if (!modalId) {
352
+ (0, _componentHelper.warn)('Modal: A valid modalId is required');
353
+ }
354
+
344
355
  if (typeof document !== 'undefined') {
345
356
  try {
346
- if (modalId) {
347
- document.documentElement.setAttribute('data-dnb-modal-active', modalId);
348
- } else {
349
- document.documentElement.removeAttribute('data-dnb-modal-active');
350
- }
351
-
352
- document.body.setAttribute('data-dnb-modal-active', modalId ? 'true' : 'false');
357
+ document.documentElement.setAttribute('data-dnb-modal-active', modalId);
358
+ document.body.setAttribute('data-dnb-modal-active', 'true');
353
359
  } catch (e) {
354
- (0, _componentHelper.warn)('Modal: Error on set "data-dnb-modal-active" by using element.setAttribute()', e);
360
+ (0, _componentHelper.warn)('Modal: Error on set "data-dnb-modal-active"', e);
355
361
  }
356
362
  }
357
363
  }
@@ -386,9 +392,9 @@ var Modal = function (_React$PureComponent) {
386
392
  trigger_class = props.trigger_class,
387
393
  rest = _objectWithoutProperties(props, _excluded);
388
394
 
389
- var _this$state2 = this.state,
390
- hide = _this$state2.hide,
391
- modalActive = _this$state2.modalActive;
395
+ var _this$state = this.state,
396
+ hide = _this$state.hide,
397
+ modalActive = _this$state.modalActive;
392
398
  var modal_content = Modal.getContent(typeof this.props.children === 'function' ? Object.freeze(_objectSpread(_objectSpread({}, this.props), {}, {
393
399
  close: this.close
394
400
  })) : this.props);
@@ -42,10 +42,10 @@ require("core-js/modules/es.object.to-string.js");
42
42
 
43
43
  require("core-js/modules/web.dom-collections.for-each.js");
44
44
 
45
- require("core-js/modules/es.regexp.exec.js");
46
-
47
45
  require("core-js/modules/es.parse-float.js");
48
46
 
47
+ require("core-js/modules/es.regexp.exec.js");
48
+
49
49
  var _react = _interopRequireDefault(require("react"));
50
50
 
51
51
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -124,6 +124,31 @@ var ModalContent = function (_React$PureComponent) {
124
124
  triggeredByEvent: null
125
125
  });
126
126
 
127
+ _defineProperty(_assertThisInitialized(_this), "lockBody", function () {
128
+ var modalRoots = getListOfModalRoots();
129
+ var firstLevel = modalRoots[0];
130
+
131
+ if (firstLevel === _assertThisInitialized(_this)) {
132
+ _this._ii = new _componentHelper.InteractionInvalidation();
133
+
134
+ _this._ii.setBypassSelector(['.dnb-modal__content *', "#dnb-modal-".concat(_this.props.root_id || 'root', " *")].filter(Boolean));
135
+
136
+ _this._ii.activate();
137
+ } else {
138
+ modalRoots.forEach(function (modal) {
139
+ if (modal !== _assertThisInitialized(_this) && typeof modal._iiLocal === 'undefined' && typeof modal._contentRef !== 'undefined') {
140
+ modal._iiLocal = new _componentHelper.InteractionInvalidation();
141
+
142
+ modal._iiLocal.activate(modal._contentRef.current);
143
+ }
144
+ });
145
+ }
146
+
147
+ if (typeof document !== 'undefined') {
148
+ document.addEventListener('keydown', _this.onKeyDownHandler);
149
+ }
150
+ });
151
+
127
152
  _defineProperty(_assertThisInitialized(_this), "_androidFocusHelper", function () {
128
153
  clearTimeout(_this._androidFocusTimeout);
129
154
  _this._androidFocusTimeout = setTimeout(function () {
@@ -134,7 +159,7 @@ var ModalContent = function (_React$PureComponent) {
134
159
  document.activeElement.scrollIntoView();
135
160
  }
136
161
  } catch (e) {}
137
- }, 100);
162
+ }, parseFloat(_this.props.animation_duration) / 2);
138
163
  });
139
164
 
140
165
  _defineProperty(_assertThisInitialized(_this), "preventClick", function (e) {
@@ -189,8 +214,6 @@ var ModalContent = function (_React$PureComponent) {
189
214
  _createClass(ModalContent, [{
190
215
  key: "componentDidMount",
191
216
  value: function componentDidMount() {
192
- var _this2 = this;
193
-
194
217
  this.addToIndex();
195
218
  this.removeScrollPossibility();
196
219
  this.setFocus();
@@ -203,9 +226,7 @@ var ModalContent = function (_React$PureComponent) {
203
226
  if ((0, _componentHelper.isTrue)(this.props.no_animation) || process.env.NODE_ENV === 'test') {
204
227
  this.lockBody();
205
228
  } else {
206
- this._lockTimeout = setTimeout(function () {
207
- _this2.lockBody();
208
- }, 500);
229
+ this._lockTimeout = setTimeout(this.lockBody, parseFloat(this.props.animation_duration) * 1.2);
209
230
  }
210
231
  }
211
232
  }, {
@@ -215,34 +236,6 @@ var ModalContent = function (_React$PureComponent) {
215
236
  clearTimeout(this._lockTimeout);
216
237
  this.removeLocks();
217
238
  }
218
- }, {
219
- key: "lockBody",
220
- value: function lockBody() {
221
- var _this3 = this;
222
-
223
- var modalRoots = getListOfModalRoots();
224
- var firstLevel = modalRoots[0];
225
-
226
- if (firstLevel === this) {
227
- this._ii = new _componentHelper.InteractionInvalidation();
228
-
229
- this._ii.setBypassSelector(['.dnb-modal__content *', "#dnb-modal-".concat(this.props.root_id || 'root', " *")].filter(Boolean));
230
-
231
- this._ii.activate();
232
- } else {
233
- modalRoots.forEach(function (modal) {
234
- if (modal !== _this3 && typeof modal._iiLocal === 'undefined' && typeof modal._contentRef !== 'undefined') {
235
- modal._iiLocal = new _componentHelper.InteractionInvalidation();
236
-
237
- modal._iiLocal.activate(modal._contentRef.current);
238
- }
239
- });
240
- }
241
-
242
- if (typeof document !== 'undefined') {
243
- document.addEventListener('keydown', this.onKeyDownHandler);
244
- }
245
- }
246
239
  }, {
247
240
  key: "removeLocks",
248
241
  value: function removeLocks() {
@@ -315,7 +308,7 @@ var ModalContent = function (_React$PureComponent) {
315
308
  }, {
316
309
  key: "removeFromIndex",
317
310
  value: function removeFromIndex() {
318
- var _this4 = this;
311
+ var _this2 = this;
319
312
 
320
313
  if (typeof window !== 'undefined') {
321
314
  try {
@@ -324,7 +317,7 @@ var ModalContent = function (_React$PureComponent) {
324
317
  }
325
318
 
326
319
  window.__modalStack = window.__modalStack.filter(function (cur) {
327
- return cur !== _this4;
320
+ return cur !== _this2;
328
321
  });
329
322
  } catch (e) {
330
323
  (0, _componentHelper.warn)(e);
@@ -379,7 +372,7 @@ var ModalContent = function (_React$PureComponent) {
379
372
  key: "closeModal",
380
373
  value: function closeModal(event, _ref) {
381
374
  var _event$persist,
382
- _this5 = this;
375
+ _this3 = this;
383
376
 
384
377
  var triggeredBy = _ref.triggeredBy,
385
378
  params = _objectWithoutProperties(_ref, _excluded);
@@ -389,7 +382,7 @@ var ModalContent = function (_React$PureComponent) {
389
382
  triggeredBy: triggeredBy,
390
383
  triggeredByEvent: event
391
384
  }, function () {
392
- _this5.props.closeModal(event, _objectSpread({
385
+ _this3.props.closeModal(event, _objectSpread({
393
386
  triggeredBy: triggeredBy
394
387
  }, params));
395
388
  });
@@ -220,26 +220,31 @@ export var useEventMapping = function useEventMapping(_ref) {
220
220
  event: event
221
221
  }, 'on_before_input');
222
222
  },
223
+ onFocus: function onFocus(params) {
224
+ return callEvent(params, 'on_focus');
225
+ },
226
+ onBlur: function onBlur(params) {
227
+ return callEvent(params, 'on_blur');
228
+ },
223
229
  onMouseUp: function onMouseUp(event) {
224
230
  return callEvent({
225
231
  event: event
226
232
  }, 'on_mouse_up');
227
233
  },
228
- on_focus: function on_focus(params) {
229
- return callEvent(params, 'on_focus');
230
- },
231
- on_key_down: function on_key_down(params) {
234
+ onKeyDown: function onKeyDown(params) {
232
235
  return callEvent(params, 'on_key_down');
233
236
  },
234
- on_submit: function on_submit(params) {
237
+ onSubmit: function onSubmit(params) {
235
238
  return callEvent(params, 'on_submit');
236
239
  },
237
- on_blur: function on_blur(params) {
238
- return callEvent(params, 'on_blur');
239
- },
240
- on_change: function on_change(params) {
240
+ onChange: function onChange(params) {
241
241
  return callEvent(params, 'on_change');
242
- }
242
+ },
243
+ on_focus: undefined,
244
+ on_blur: undefined,
245
+ on_key_down: undefined,
246
+ on_submit: undefined,
247
+ on_change: undefined
243
248
  };
244
249
  };
245
250
 
@@ -250,11 +255,7 @@ var useCallEvent = function useCallEvent(_ref2) {
250
255
  props = _React$useContext8.props;
251
256
 
252
257
  var maskParams = useMaskParams();
253
-
254
- if (!maskParams) {
255
- return function () {};
256
- }
257
-
258
+ var isNumberMask = useNumberMask();
258
259
  var decimalSeparators = /[,.'·]/;
259
260
  var isUnidentified = false;
260
261
 
@@ -275,7 +276,7 @@ var useCallEvent = function useCallEvent(_ref2) {
275
276
  isUnidentified = false;
276
277
  }
277
278
 
278
- if (name === 'on_key_down' && !isUnidentified && !(maskParams !== null && maskParams !== void 0 && maskParams.allowLeadingZeroes) && (keyCode === '0' || value.replace(/[^\d]/g, '') === '' && decimalSeparators.test(keyCode))) {
279
+ if (name === 'on_key_down' && !isUnidentified && (isNumberMask && !(maskParams !== null && maskParams !== void 0 && maskParams.allowLeadingZeroes) || !isNumberMask && (maskParams === null || maskParams === void 0 ? void 0 : maskParams.allowLeadingZeroes) === false) && (keyCode === '0' || keyCode === 'numpad 0' || value.replace(/[^\d]/g, '') === '' && decimalSeparators.test(keyCode))) {
279
280
  var testValue = (value.slice(0, selStart) + '0' + value.slice(selStart + 1, value.length)).replace(/[^\d]/g, '');
280
281
 
281
282
  if (/^0/.test(testValue)) {
@@ -284,7 +285,7 @@ var useCallEvent = function useCallEvent(_ref2) {
284
285
  }
285
286
  }
286
287
 
287
- if (name === 'on_key_down' && !isUnidentified && maskParams !== null && maskParams !== void 0 && maskParams.decimalSymbol) {
288
+ if (name === 'on_key_down' && isNumberMask && !isUnidentified && maskParams !== null && maskParams !== void 0 && maskParams.decimalSymbol) {
288
289
  var hasDecimalSymbol = value.includes(maskParams.decimalSymbol);
289
290
  var allowedDecimals = maskParams.decimalLimit > 0 || maskParams.allowDecimal !== false;
290
291
 
@@ -242,6 +242,10 @@ export interface ModalProps extends React.HTMLProps<HTMLElement> {
242
242
  * Set a function to call the callback function, once the modal/drawer should close: `close_modal={(close) => close()}`
243
243
  */
244
244
  close_modal?: (...args: any[]) => any;
245
+
246
+ /**
247
+ * Provide a custom trigger component. Like `trigger={<Anchor href="/" />}`. It will set the focus on it when the modal/drawer gets closed.
248
+ */
245
249
  trigger?: ModalTrigger;
246
250
 
247
251
  /**
@@ -94,7 +94,6 @@ var Modal = function (_React$PureComponent) {
94
94
  hide: true
95
95
  });
96
96
 
97
- clearTimeout(_this._closeTimeout);
98
97
  _this._closeTimeout = setTimeout(doItNow, parseFloat(_this.props.animation_duration));
99
98
  } else {
100
99
  doItNow();
@@ -105,13 +104,14 @@ var Modal = function (_React$PureComponent) {
105
104
  var delay = parseFloat(_this.props.open_delay);
106
105
 
107
106
  if (delay > 0 && !isTrue(_this.props.no_animation)) {
108
- clearTimeout(_this._openTimeout);
109
107
  _this._openTimeout = setTimeout(toggleNow, delay);
110
108
  } else {
111
109
  toggleNow();
112
110
  }
113
111
  };
114
112
 
113
+ clearTimeout(_this._closeTimeout);
114
+ clearTimeout(_this._openTimeout);
115
115
  var open_modal = _this.props.open_modal;
116
116
 
117
117
  if (typeof open_modal === 'function') {
@@ -157,13 +157,7 @@ var Modal = function (_React$PureComponent) {
157
157
  } catch (e) {}
158
158
  }
159
159
 
160
- var last = getListOfModalRoots(-1);
161
-
162
- if (last) {
163
- _this.setActiveState(last._id);
164
- } else if (getListOfModalRoots().length <= 1) {
165
- _this.setActiveState(false);
166
- }
160
+ _this.removeActiveState();
167
161
  }
168
162
  });
169
163
 
@@ -221,16 +215,15 @@ var Modal = function (_React$PureComponent) {
221
215
  }, {
222
216
  key: "componentWillUnmount",
223
217
  value: function componentWillUnmount() {
218
+ clearTimeout(this._openTimeout);
219
+ clearTimeout(this._closeTimeout);
220
+ this.removeActiveState(false);
221
+
224
222
  this._onUnmount.forEach(function (fn) {
225
223
  if (typeof fn === 'function') {
226
224
  fn();
227
225
  }
228
226
  });
229
-
230
- clearTimeout(this._openTimeout);
231
- clearTimeout(this._closeTimeout);
232
- clearTimeout(this._sideEffectsTimeout);
233
- clearTimeout(this._tryToOpenTimeout);
234
227
  }
235
228
  }, {
236
229
  key: "componentDidUpdate",
@@ -242,35 +235,48 @@ var Modal = function (_React$PureComponent) {
242
235
  }, {
243
236
  key: "openBasedOnStateUpdate",
244
237
  value: function openBasedOnStateUpdate() {
245
- var _this$state = this.state,
246
- hide = _this$state.hide,
247
- modalActive = _this$state.modalActive;
238
+ var hide = this.state.hide;
248
239
  var open_state = this.props.open_state;
249
240
 
250
241
  if (!this.activeElement && typeof document !== 'undefined') {
251
242
  this.activeElement = document.activeElement;
252
243
  }
253
244
 
254
- if (!hide && !modalActive && (open_state === 'opened' || open_state === true)) {
245
+ if (!hide && (open_state === 'opened' || open_state === true)) {
255
246
  this.toggleOpenClose(null, true);
256
- } else if (hide && modalActive && (open_state === 'closed' || open_state === false)) {
247
+ } else if (hide && (open_state === 'closed' || open_state === false)) {
257
248
  this.toggleOpenClose(null, false);
258
249
  }
259
250
  }
251
+ }, {
252
+ key: "removeActiveState",
253
+ value: function removeActiveState() {
254
+ var last = getListOfModalRoots(-1);
255
+
256
+ if (last !== null && last !== void 0 && last._id && last._id !== this._id) {
257
+ return this.setActiveState(last._id);
258
+ }
259
+
260
+ try {
261
+ document.documentElement.removeAttribute('data-dnb-modal-active');
262
+ document.body.setAttribute('data-dnb-modal-active', 'false');
263
+ } catch (e) {
264
+ warn('Modal: Error on remove "data-dnb-modal-active"', e);
265
+ }
266
+ }
260
267
  }, {
261
268
  key: "setActiveState",
262
269
  value: function setActiveState(modalId) {
270
+ if (!modalId) {
271
+ warn('Modal: A valid modalId is required');
272
+ }
273
+
263
274
  if (typeof document !== 'undefined') {
264
275
  try {
265
- if (modalId) {
266
- document.documentElement.setAttribute('data-dnb-modal-active', modalId);
267
- } else {
268
- document.documentElement.removeAttribute('data-dnb-modal-active');
269
- }
270
-
271
- document.body.setAttribute('data-dnb-modal-active', modalId ? 'true' : 'false');
276
+ document.documentElement.setAttribute('data-dnb-modal-active', modalId);
277
+ document.body.setAttribute('data-dnb-modal-active', 'true');
272
278
  } catch (e) {
273
- warn('Modal: Error on set "data-dnb-modal-active" by using element.setAttribute()', e);
279
+ warn('Modal: Error on set "data-dnb-modal-active"', e);
274
280
  }
275
281
  }
276
282
  }
@@ -305,9 +311,9 @@ var Modal = function (_React$PureComponent) {
305
311
  trigger_class = props.trigger_class,
306
312
  rest = _objectWithoutProperties(props, _excluded);
307
313
 
308
- var _this$state2 = this.state,
309
- hide = _this$state2.hide,
310
- modalActive = _this$state2.modalActive;
314
+ var _this$state = this.state,
315
+ hide = _this$state.hide,
316
+ modalActive = _this$state.modalActive;
311
317
  var modal_content = Modal.getContent(typeof this.props.children === 'function' ? Object.freeze(_objectSpread(_objectSpread({}, this.props), {}, {
312
318
  close: this.close
313
319
  })) : this.props);