@squiz/formatted-text-editor 1.21.1-alpha.29 → 1.21.1-alpha.30
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/lib/ui/Modal/Modal.js
CHANGED
@@ -32,6 +32,7 @@ const CloseRounded_1 = __importDefault(require("@mui/icons-material/CloseRounded
|
|
32
32
|
const base_1 = require("@mui/base");
|
33
33
|
const clsx_1 = __importDefault(require("clsx"));
|
34
34
|
const Modal = ({ children, title, onCancel, onSubmit, className }, ref) => {
|
35
|
+
const content = (0, react_1.useRef)(null);
|
35
36
|
const container = (0, react_1.useMemo)(() => {
|
36
37
|
const element = document.createElement('div');
|
37
38
|
element.classList.add('squiz-fte-scope');
|
@@ -52,7 +53,7 @@ const Modal = ({ children, title, onCancel, onSubmit, className }, ref) => {
|
|
52
53
|
}, []);
|
53
54
|
// add/remove the modal container from the DOM and focus on the first input
|
54
55
|
(0, react_1.useEffect)(() => {
|
55
|
-
const firstInput =
|
56
|
+
const firstInput = content.current?.querySelector('input:not([type=hidden]), button');
|
56
57
|
document.body.appendChild(container);
|
57
58
|
firstInput?.focus();
|
58
59
|
return () => {
|
@@ -68,7 +69,7 @@ const Modal = ({ children, title, onCancel, onSubmit, className }, ref) => {
|
|
68
69
|
react_1.default.createElement("h2", { className: "font-semibold text-gray-900 text-heading-2" }, title),
|
69
70
|
react_1.default.createElement("button", { type: "button", className: "ml-auto -mr-3 -mt-3 bg-transparent border-0 text-gray-600 font-semibold outline-none focus:outline-none hover:text-color-gray-800", onClick: onCancel, "aria-label": "Close" },
|
70
71
|
react_1.default.createElement(CloseRounded_1.default, null))),
|
71
|
-
react_1.default.createElement("div", { className: "squiz-fte-modal-content" }, children),
|
72
|
+
react_1.default.createElement("div", { className: "squiz-fte-modal-content", ref: content }, children),
|
72
73
|
react_1.default.createElement("div", { className: "squiz-fte-modal-footer p-6 pt-3" },
|
73
74
|
react_1.default.createElement("button", { className: "squiz-fte-modal-footer__button bg-gray-200 text-gray-700 mr-2 hover:bg-gray-300", type: "button", onClick: onCancel, "aria-label": "Cancel" }, "Cancel"),
|
74
75
|
onSubmit && (react_1.default.createElement("button", { className: "squiz-fte-modal-footer__button bg-blue-300 text-white hover:bg-blue-400", type: "button", onClick: onSubmit, "aria-label": "Apply" }, "Apply"))))))),
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@squiz/formatted-text-editor",
|
3
|
-
"version": "1.21.1-alpha.
|
3
|
+
"version": "1.21.1-alpha.30",
|
4
4
|
"main": "lib/index.js",
|
5
5
|
"types": "lib/index.d.ts",
|
6
6
|
"scripts": {
|
@@ -74,5 +74,5 @@
|
|
74
74
|
"volta": {
|
75
75
|
"node": "18.15.0"
|
76
76
|
},
|
77
|
-
"gitHead": "
|
77
|
+
"gitHead": "f5498d948f7c520758c3cbc1d11416f924d521aa"
|
78
78
|
}
|
@@ -2,6 +2,8 @@ import '@testing-library/jest-dom';
|
|
2
2
|
import { render, screen, fireEvent } from '@testing-library/react';
|
3
3
|
import React from 'react';
|
4
4
|
import Modal from './Modal';
|
5
|
+
import { Select } from '../Fields/Select/Select';
|
6
|
+
import { Input } from '../Fields/Input/Input';
|
5
7
|
|
6
8
|
describe('Modal', () => {
|
7
9
|
const mockOnCancel = jest.fn();
|
@@ -110,4 +112,17 @@ describe('Modal', () => {
|
|
110
112
|
|
111
113
|
expect(screen.getByLabelText('My input')).toHaveFocus();
|
112
114
|
});
|
115
|
+
|
116
|
+
it('Auto-focuses on the first select field on mount', () => {
|
117
|
+
render(
|
118
|
+
<Modal title="Modal title" onCancel={mockOnCancel} onSubmit={mockOnSubmit}>
|
119
|
+
<>
|
120
|
+
<Select label="Dropdown" name="select" options={{}} />
|
121
|
+
<Input label="Input" name="input" />
|
122
|
+
</>
|
123
|
+
</Modal>,
|
124
|
+
);
|
125
|
+
|
126
|
+
expect(screen.getByLabelText('Dropdown')).toHaveFocus();
|
127
|
+
});
|
113
128
|
});
|
package/src/ui/Modal/Modal.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { ForwardedRef, forwardRef, ReactElement, useEffect, useMemo } from 'react';
|
1
|
+
import React, { ForwardedRef, forwardRef, ReactElement, useEffect, useMemo, useRef } from 'react';
|
2
2
|
import { createPortal } from 'react-dom';
|
3
3
|
import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
|
4
4
|
import { FocusTrap } from '@mui/base';
|
@@ -16,6 +16,7 @@ const Modal = (
|
|
16
16
|
{ children, title, onCancel, onSubmit, className }: ModalProps,
|
17
17
|
ref: ForwardedRef<HTMLDivElement>,
|
18
18
|
): ReactElement => {
|
19
|
+
const content = useRef<HTMLDivElement>(null);
|
19
20
|
const container = useMemo(() => {
|
20
21
|
const element = document.createElement('div');
|
21
22
|
element.classList.add('squiz-fte-scope');
|
@@ -38,7 +39,7 @@ const Modal = (
|
|
38
39
|
|
39
40
|
// add/remove the modal container from the DOM and focus on the first input
|
40
41
|
useEffect(() => {
|
41
|
-
const firstInput =
|
42
|
+
const firstInput = content.current?.querySelector('input:not([type=hidden]), button') as HTMLElement;
|
42
43
|
|
43
44
|
document.body.appendChild(container);
|
44
45
|
firstInput?.focus();
|
@@ -65,7 +66,9 @@ const Modal = (
|
|
65
66
|
<CloseRoundedIcon />
|
66
67
|
</button>
|
67
68
|
</div>
|
68
|
-
<div className="squiz-fte-modal-content"
|
69
|
+
<div className="squiz-fte-modal-content" ref={content}>
|
70
|
+
{children}
|
71
|
+
</div>
|
69
72
|
<div className="squiz-fte-modal-footer p-6 pt-3">
|
70
73
|
<button
|
71
74
|
className="squiz-fte-modal-footer__button bg-gray-200 text-gray-700 mr-2 hover:bg-gray-300"
|
File without changes
|