rsuite 4.10.5 → 4.10.6
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 +11 -0
- package/dist/rsuite.js +27 -3
- package/dist/rsuite.min.js +10 -2
- package/dist/rsuite.min.js.map +1 -1
- package/es/Modal/BaseModal.js +24 -4
- package/es/Modal/ModalDialog.js +1 -0
- package/lib/Modal/BaseModal.js +24 -4
- package/lib/Modal/ModalDialog.js +1 -0
- package/package.json +3 -3
- package/src/Modal/BaseModal.tsx +26 -4
- package/src/Modal/ModalDialog.tsx +1 -0
- package/src/Modal/test/ModalSpec.js +5 -0
package/es/Modal/BaseModal.js
CHANGED
|
@@ -48,6 +48,7 @@ function (_React$Component2) {
|
|
|
48
48
|
_this.lastFocus = null;
|
|
49
49
|
_this.onDocumentKeyupListener = null;
|
|
50
50
|
_this.onFocusinListener = null;
|
|
51
|
+
_this._isMounted = null;
|
|
51
52
|
|
|
52
53
|
_this.setMountNodeRef = function (ref) {
|
|
53
54
|
var _ref$getMountNode;
|
|
@@ -95,15 +96,30 @@ function (_React$Component2) {
|
|
|
95
96
|
_this.enforceFocus = function () {
|
|
96
97
|
var enforceFocus = _this.props.enforceFocus;
|
|
97
98
|
|
|
98
|
-
if (!enforceFocus || !_this.isTopModal()) {
|
|
99
|
+
if (!enforceFocus || !_this._isMounted || !_this.isTopModal()) {
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
var
|
|
103
|
+
var currentActiveElement = activeElement(ownerDocument(_assertThisInitialized(_this)));
|
|
103
104
|
|
|
104
105
|
var modal = _this.getDialogElement();
|
|
105
106
|
|
|
106
|
-
if (modal && modal !==
|
|
107
|
+
if (modal && modal !== currentActiveElement && !contains(modal, currentActiveElement)) {
|
|
108
|
+
modal.focus();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
_this.handlePortalRendered = function () {
|
|
113
|
+
if (!_this.props.autoFocus) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
var modal = _this.getDialogElement();
|
|
118
|
+
|
|
119
|
+
var currentActiveElement = activeElement(ownerDocument(_assertThisInitialized(_this)));
|
|
120
|
+
|
|
121
|
+
if (modal && modal !== currentActiveElement && !contains(modal, currentActiveElement)) {
|
|
122
|
+
_this.lastFocus = currentActiveElement;
|
|
107
123
|
modal.focus();
|
|
108
124
|
}
|
|
109
125
|
};
|
|
@@ -120,6 +136,8 @@ function (_React$Component2) {
|
|
|
120
136
|
var _proto2 = BaseModal.prototype;
|
|
121
137
|
|
|
122
138
|
_proto2.componentDidMount = function componentDidMount() {
|
|
139
|
+
this._isMounted = true;
|
|
140
|
+
|
|
123
141
|
if (this.props.show) {
|
|
124
142
|
this.onShow();
|
|
125
143
|
}
|
|
@@ -163,6 +181,7 @@ function (_React$Component2) {
|
|
|
163
181
|
var _this$props4 = this.props,
|
|
164
182
|
show = _this$props4.show,
|
|
165
183
|
transition = _this$props4.transition;
|
|
184
|
+
this._isMounted = false;
|
|
166
185
|
|
|
167
186
|
if (show || transition && !this.state.exited) {
|
|
168
187
|
this.onHide();
|
|
@@ -293,7 +312,8 @@ function (_React$Component2) {
|
|
|
293
312
|
|
|
294
313
|
return React.createElement(Portal, {
|
|
295
314
|
ref: this.setMountNodeRef,
|
|
296
|
-
container: container
|
|
315
|
+
container: container,
|
|
316
|
+
onRendered: this.handlePortalRendered
|
|
297
317
|
}, React.createElement("div", {
|
|
298
318
|
ref: this.modalNodeRef,
|
|
299
319
|
role: rest.role,
|
package/es/Modal/ModalDialog.js
CHANGED
package/lib/Modal/BaseModal.js
CHANGED
|
@@ -69,6 +69,7 @@ function (_React$Component2) {
|
|
|
69
69
|
_this.lastFocus = null;
|
|
70
70
|
_this.onDocumentKeyupListener = null;
|
|
71
71
|
_this.onFocusinListener = null;
|
|
72
|
+
_this._isMounted = null;
|
|
72
73
|
|
|
73
74
|
_this.setMountNodeRef = function (ref) {
|
|
74
75
|
var _ref$getMountNode;
|
|
@@ -116,15 +117,30 @@ function (_React$Component2) {
|
|
|
116
117
|
_this.enforceFocus = function () {
|
|
117
118
|
var enforceFocus = _this.props.enforceFocus;
|
|
118
119
|
|
|
119
|
-
if (!enforceFocus || !_this.isTopModal()) {
|
|
120
|
+
if (!enforceFocus || !_this._isMounted || !_this.isTopModal()) {
|
|
120
121
|
return;
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
var
|
|
124
|
+
var currentActiveElement = (0, _domLib.activeElement)((0, _domLib.ownerDocument)((0, _assertThisInitialized2.default)(_this)));
|
|
124
125
|
|
|
125
126
|
var modal = _this.getDialogElement();
|
|
126
127
|
|
|
127
|
-
if (modal && modal !==
|
|
128
|
+
if (modal && modal !== currentActiveElement && !(0, _domLib.contains)(modal, currentActiveElement)) {
|
|
129
|
+
modal.focus();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
_this.handlePortalRendered = function () {
|
|
134
|
+
if (!_this.props.autoFocus) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
var modal = _this.getDialogElement();
|
|
139
|
+
|
|
140
|
+
var currentActiveElement = (0, _domLib.activeElement)((0, _domLib.ownerDocument)((0, _assertThisInitialized2.default)(_this)));
|
|
141
|
+
|
|
142
|
+
if (modal && modal !== currentActiveElement && !(0, _domLib.contains)(modal, currentActiveElement)) {
|
|
143
|
+
_this.lastFocus = currentActiveElement;
|
|
128
144
|
modal.focus();
|
|
129
145
|
}
|
|
130
146
|
};
|
|
@@ -141,6 +157,8 @@ function (_React$Component2) {
|
|
|
141
157
|
var _proto2 = BaseModal.prototype;
|
|
142
158
|
|
|
143
159
|
_proto2.componentDidMount = function componentDidMount() {
|
|
160
|
+
this._isMounted = true;
|
|
161
|
+
|
|
144
162
|
if (this.props.show) {
|
|
145
163
|
this.onShow();
|
|
146
164
|
}
|
|
@@ -184,6 +202,7 @@ function (_React$Component2) {
|
|
|
184
202
|
var _this$props4 = this.props,
|
|
185
203
|
show = _this$props4.show,
|
|
186
204
|
transition = _this$props4.transition;
|
|
205
|
+
this._isMounted = false;
|
|
187
206
|
|
|
188
207
|
if (show || transition && !this.state.exited) {
|
|
189
208
|
this.onHide();
|
|
@@ -312,7 +331,8 @@ function (_React$Component2) {
|
|
|
312
331
|
|
|
313
332
|
return React.createElement(_Portal.default, {
|
|
314
333
|
ref: this.setMountNodeRef,
|
|
315
|
-
container: container
|
|
334
|
+
container: container,
|
|
335
|
+
onRendered: this.handlePortalRendered
|
|
316
336
|
}, React.createElement("div", {
|
|
317
337
|
ref: this.modalNodeRef,
|
|
318
338
|
role: rest.role,
|
package/lib/Modal/ModalDialog.js
CHANGED
|
@@ -82,6 +82,7 @@ function (_React$Component) {
|
|
|
82
82
|
return React.createElement("div", (0, _extends2.default)({}, props, {
|
|
83
83
|
title: null,
|
|
84
84
|
role: "dialog",
|
|
85
|
+
tabIndex: -1,
|
|
85
86
|
ref: (0, _mergeRefs.default)(this.bindHtmlRef, dialogRef),
|
|
86
87
|
className: (0, _classnames.default)(classPrefix, className),
|
|
87
88
|
style: modalStyle
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rsuite",
|
|
3
|
-
"version": "4.10.
|
|
3
|
+
"version": "4.10.6",
|
|
4
4
|
"description": "A suite of react components",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"prop-types": "^15.7.2",
|
|
64
64
|
"react-lifecycles-compat": "^3.0.4",
|
|
65
65
|
"react-virtualized": "^9.21.0",
|
|
66
|
-
"rsuite-table": "^3.
|
|
66
|
+
"rsuite-table": "^3.16.0",
|
|
67
67
|
"schema-typed": "^1.5.1"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"css-loader": "^0.28.11",
|
|
113
113
|
"cssnano": "^4.1.10",
|
|
114
114
|
"del": "^3.0.0",
|
|
115
|
-
"dtslint": "^
|
|
115
|
+
"dtslint": "^4.2.1",
|
|
116
116
|
"enzyme": "^3.3.0",
|
|
117
117
|
"enzyme-adapter-react-16": "^1.1.1",
|
|
118
118
|
"eslint": "^6.7.2",
|
package/src/Modal/BaseModal.tsx
CHANGED
|
@@ -50,6 +50,7 @@ class BaseModal extends React.Component<BaseModalProps, BaseModalState> {
|
|
|
50
50
|
lastFocus = null;
|
|
51
51
|
onDocumentKeyupListener = null;
|
|
52
52
|
onFocusinListener = null;
|
|
53
|
+
_isMounted = null;
|
|
53
54
|
|
|
54
55
|
constructor(props: BaseModalProps) {
|
|
55
56
|
super(props);
|
|
@@ -59,6 +60,7 @@ class BaseModal extends React.Component<BaseModalProps, BaseModalState> {
|
|
|
59
60
|
this.dialogRef = React.createRef();
|
|
60
61
|
}
|
|
61
62
|
componentDidMount() {
|
|
63
|
+
this._isMounted = true;
|
|
62
64
|
if (this.props.show) {
|
|
63
65
|
this.onShow();
|
|
64
66
|
}
|
|
@@ -95,6 +97,8 @@ class BaseModal extends React.Component<BaseModalProps, BaseModalState> {
|
|
|
95
97
|
componentWillUnmount() {
|
|
96
98
|
const { show, transition } = this.props;
|
|
97
99
|
|
|
100
|
+
this._isMounted = false;
|
|
101
|
+
|
|
98
102
|
if (show || (transition && !this.state.exited)) {
|
|
99
103
|
this.onHide();
|
|
100
104
|
}
|
|
@@ -173,14 +177,28 @@ class BaseModal extends React.Component<BaseModalProps, BaseModalState> {
|
|
|
173
177
|
enforceFocus = () => {
|
|
174
178
|
const { enforceFocus } = this.props;
|
|
175
179
|
|
|
176
|
-
if (!enforceFocus || !this.isTopModal()) {
|
|
180
|
+
if (!enforceFocus || !this._isMounted || !this.isTopModal()) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const currentActiveElement = activeElement(ownerDocument(this));
|
|
185
|
+
const modal = this.getDialogElement();
|
|
186
|
+
|
|
187
|
+
if (modal && modal !== currentActiveElement && !contains(modal, currentActiveElement)) {
|
|
188
|
+
modal.focus();
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
handlePortalRendered = () => {
|
|
193
|
+
if (!this.props.autoFocus) {
|
|
177
194
|
return;
|
|
178
195
|
}
|
|
179
196
|
|
|
180
|
-
const active = activeElement(ownerDocument(this));
|
|
181
197
|
const modal = this.getDialogElement();
|
|
198
|
+
const currentActiveElement = activeElement(ownerDocument(this));
|
|
182
199
|
|
|
183
|
-
if (modal && modal !==
|
|
200
|
+
if (modal && modal !== currentActiveElement && !contains(modal, currentActiveElement)) {
|
|
201
|
+
this.lastFocus = currentActiveElement;
|
|
184
202
|
modal.focus();
|
|
185
203
|
}
|
|
186
204
|
};
|
|
@@ -268,7 +286,11 @@ class BaseModal extends React.Component<BaseModalProps, BaseModalState> {
|
|
|
268
286
|
}
|
|
269
287
|
|
|
270
288
|
return (
|
|
271
|
-
<Portal
|
|
289
|
+
<Portal
|
|
290
|
+
ref={this.setMountNodeRef}
|
|
291
|
+
container={container}
|
|
292
|
+
onRendered={this.handlePortalRendered}
|
|
293
|
+
>
|
|
272
294
|
<div ref={this.modalNodeRef} role={rest.role} style={style} className={className}>
|
|
273
295
|
{backdrop && this.renderBackdrop()}
|
|
274
296
|
<RefHolder ref={this.dialogRef}>{dialog}</RefHolder>
|
|
@@ -124,4 +124,9 @@ describe('Modal', () => {
|
|
|
124
124
|
const instance = getInstance(<Modal classPrefix="custom-prefix" show />);
|
|
125
125
|
assert.ok(instance.dialogElement.className.match(/\bcustom-prefix\b/));
|
|
126
126
|
});
|
|
127
|
+
|
|
128
|
+
it('Should be forced to focus on Modal', () => {
|
|
129
|
+
const instance = getInstance(<Modal className="custom" show />);
|
|
130
|
+
assert.equal(instance.dialogElement, document.activeElement);
|
|
131
|
+
});
|
|
127
132
|
});
|