carbon-react 111.12.0 → 111.12.1
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
|
-
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import classNames from "classnames";
|
|
5
5
|
import { TransitionGroup, CSSTransition } from "react-transition-group";
|
|
6
6
|
import PropTypes from "prop-types";
|
|
@@ -32,6 +32,7 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
32
32
|
const toastContentNodeRef = useRef();
|
|
33
33
|
const closeIconRef = useRef();
|
|
34
34
|
const focusedElementBeforeOpening = useRef();
|
|
35
|
+
const [tabIndex, setTabIndex] = useState(0);
|
|
35
36
|
const refToPass = ref || toastRef;
|
|
36
37
|
const componentClasses = useMemo(() => {
|
|
37
38
|
return classNames(className);
|
|
@@ -53,15 +54,16 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
53
54
|
timer.current = setTimeout(() => onDismiss(), timeout);
|
|
54
55
|
}, [onDismiss, open, timeout]);
|
|
55
56
|
useEffect(() => {
|
|
56
|
-
if (
|
|
57
|
+
if (!disableAutoFocus) {
|
|
57
58
|
if (open) {
|
|
58
|
-
var
|
|
59
|
+
var _toastContentNodeRef$;
|
|
59
60
|
|
|
60
61
|
focusedElementBeforeOpening.current = document.activeElement;
|
|
61
|
-
(
|
|
62
|
+
(_toastContentNodeRef$ = toastContentNodeRef.current) === null || _toastContentNodeRef$ === void 0 ? void 0 : _toastContentNodeRef$.focus();
|
|
62
63
|
} else if (focusedElementBeforeOpening.current) {
|
|
63
64
|
focusedElementBeforeOpening.current.focus();
|
|
64
65
|
focusedElementBeforeOpening.current = undefined;
|
|
66
|
+
setTabIndex(0);
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
}, [open, onDismiss, disableAutoFocus]);
|
|
@@ -107,6 +109,9 @@ const Toast = /*#__PURE__*/React.forwardRef(({
|
|
|
107
109
|
className: componentClasses
|
|
108
110
|
}, tagComponent(restProps["data-component"] || "toast", restProps), toastProps, {
|
|
109
111
|
ref: toastContentNodeRef
|
|
112
|
+
}, !disableAutoFocus && {
|
|
113
|
+
tabIndex,
|
|
114
|
+
onBlur: () => setTabIndex(undefined)
|
|
110
115
|
}), !isNotice && /*#__PURE__*/React.createElement(TypeIcon, {
|
|
111
116
|
variant: toastProps.variant
|
|
112
117
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
@@ -50,8 +50,11 @@ const ToastStyle = styled(MessageStyle)`
|
|
|
50
50
|
margin-right: ${isCenter ? "auto" : "30px"};
|
|
51
51
|
`}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
:focus {
|
|
54
|
+
outline: none;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&${animationName}-appear, &${animationName}-enter {
|
|
55
58
|
opacity: 0;
|
|
56
59
|
transform: scale(0.5);
|
|
57
60
|
}
|
|
@@ -56,6 +56,7 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
56
56
|
const toastContentNodeRef = (0, _react.useRef)();
|
|
57
57
|
const closeIconRef = (0, _react.useRef)();
|
|
58
58
|
const focusedElementBeforeOpening = (0, _react.useRef)();
|
|
59
|
+
const [tabIndex, setTabIndex] = (0, _react.useState)(0);
|
|
59
60
|
const refToPass = ref || toastRef;
|
|
60
61
|
const componentClasses = (0, _react.useMemo)(() => {
|
|
61
62
|
return (0, _classnames.default)(className);
|
|
@@ -77,15 +78,16 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
77
78
|
timer.current = setTimeout(() => onDismiss(), timeout);
|
|
78
79
|
}, [onDismiss, open, timeout]);
|
|
79
80
|
(0, _react.useEffect)(() => {
|
|
80
|
-
if (
|
|
81
|
+
if (!disableAutoFocus) {
|
|
81
82
|
if (open) {
|
|
82
|
-
var
|
|
83
|
+
var _toastContentNodeRef$;
|
|
83
84
|
|
|
84
85
|
focusedElementBeforeOpening.current = document.activeElement;
|
|
85
|
-
(
|
|
86
|
+
(_toastContentNodeRef$ = toastContentNodeRef.current) === null || _toastContentNodeRef$ === void 0 ? void 0 : _toastContentNodeRef$.focus();
|
|
86
87
|
} else if (focusedElementBeforeOpening.current) {
|
|
87
88
|
focusedElementBeforeOpening.current.focus();
|
|
88
89
|
focusedElementBeforeOpening.current = undefined;
|
|
90
|
+
setTabIndex(0);
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
}, [open, onDismiss, disableAutoFocus]);
|
|
@@ -131,6 +133,9 @@ const Toast = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
131
133
|
className: componentClasses
|
|
132
134
|
}, (0, _tags.default)(restProps["data-component"] || "toast", restProps), toastProps, {
|
|
133
135
|
ref: toastContentNodeRef
|
|
136
|
+
}, !disableAutoFocus && {
|
|
137
|
+
tabIndex,
|
|
138
|
+
onBlur: () => setTabIndex(undefined)
|
|
134
139
|
}), !isNotice && /*#__PURE__*/_react.default.createElement(_toast.TypeIcon, {
|
|
135
140
|
variant: toastProps.variant
|
|
136
141
|
}, /*#__PURE__*/_react.default.createElement(_icon.default, {
|
|
@@ -78,8 +78,11 @@ const ToastStyle = (0, _styledComponents.default)(_message.default)`
|
|
|
78
78
|
margin-right: ${isCenter ? "auto" : "30px"};
|
|
79
79
|
`}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
:focus {
|
|
82
|
+
outline: none;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&${animationName}-appear, &${animationName}-enter {
|
|
83
86
|
opacity: 0;
|
|
84
87
|
transform: scale(0.5);
|
|
85
88
|
}
|