Skip to content

Commit fd1e6f1

Browse files
committed
chore: merge master
2 parents 48c9c2a + da62840 commit fd1e6f1

File tree

15 files changed

+138
-52
lines changed

15 files changed

+138
-52
lines changed

.dumirc.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from 'dumi';
2+
import path from 'path';
3+
4+
export default defineConfig({
5+
alias: {
6+
'rc-dialog$': path.resolve('src'),
7+
'rc-dialog/es': path.resolve('src'),
8+
},
9+
favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'],
10+
themeConfig: {
11+
name: 'Dialog',
12+
logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4',
13+
},
14+
});;

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ package-lock.json
4141
.umi-production
4242
.umi-test
4343
.env.local
44+
45+
46+
# dumi
47+
.dumi/tmp
48+
.dumi/tmp-production

.umirc.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@
22

33
react dialog component
44

5-
[![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Test coverage][coveralls-image]][coveralls-url] [![Dependencies][david-image]][david-url] [![DevDependencies][david-dev-image]][david-dev-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
5+
[![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Test coverage][coveralls-image]][coveralls-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
66

77
[npm-image]: http://img.shields.io/npm/v/rc-dialog.svg?style=flat-square
88
[npm-url]: http://npmjs.org/package/rc-dialog
99
[github-actions-image]: https://github.com/react-component/dialog/workflows/CI/badge.svg
1010
[github-actions-url]: https://github.com/react-component/dialog/actions
1111
[circleci-image]: https://img.shields.io/circleci/react-component/dialog/master?style=flat-square
1212
[circleci-url]: https://circleci.com/gh/react-component/dialog
13-
[coveralls-image]: https://img.shields.io/coveralls/react-component/dialog.svg?style=flat-square
14-
[coveralls-url]: https://coveralls.io/r/react-component/dialog?branch=master
15-
[david-url]: https://david-dm.org/react-component/dialog
16-
[david-image]: https://david-dm.org/react-component/dialog/status.svg?style=flat-square
17-
[david-dev-url]: https://david-dm.org/react-component/dialog?type=dev
18-
[david-dev-image]: https://david-dm.org/react-component/dialog/dev-status.svg?style=flat-square
13+
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/dialog/master.svg?style=flat-square
14+
[codecov-url]: https://app.codecov.io/gh/react-component/dialog
1915
[download-image]: https://img.shields.io/npm/dm/rc-dialog.svg?style=flat-square
2016
[download-url]: https://npmjs.org/package/rc-dialog
2117
[bundlephobia-url]: https://bundlephobia.com/result?p=rc-dialog

docs/demo/ant-design.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
## ant-design
1+
---
2+
title: ant-design
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
27

3-
<code src="../examples/ant-design.tsx">
8+
<code src="../examples/ant-design.tsx"></code>

docs/demo/bootstrap.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
## bootstrap
1+
---
2+
title: bootstrap
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
27

3-
<code src="../examples/bootstrap.tsx">
8+
<code src="../examples/bootstrap.tsx"></code>

docs/demo/draggable.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
## draggable
1+
---
2+
title: draggable
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
27

3-
<code src="../examples/draggable.tsx">
8+
<code src="../examples/draggable.tsx"></code>

docs/demo/multiple-Portal.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
## multiple-Portal
1+
---
2+
title: multiple-Portal
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
27

3-
<code src="../examples/multiple-Portal.tsx">
8+
<code src="../examples/multiple-Portal.tsx"></code>

docs/demo/pure.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
## pure-debug
1+
---
2+
title: pure-debug
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
27

3-
<code src="../examples/pure.tsx">
8+
<code src="../examples/pure.tsx"></code>

docs/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
2-
title: rc-dialog
2+
hero:
3+
title: rc-dialog
4+
description: React Dialog Component
35
---
46

57
<embed src="../README.md"></embed>

now.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"src": "package.json",
77
"use": "@now/static-build",
8-
"config": { "distDir": ".doc" }
8+
"config": { "distDir": "dist" }
99
}
1010
],
1111
"routes": [

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-dialog",
3-
"version": "9.0.1",
3+
"version": "9.0.2",
44
"description": "dialog ui component for react",
55
"keywords": [
66
"react",
@@ -59,12 +59,12 @@
5959
"@types/jest": "^26.0.14",
6060
"@types/keyv": "3.1.4",
6161
"@types/react": "^18.0.24",
62-
"@types/react-dom": "^17.0.9",
63-
"@umijs/fabric": "^2.0.0",
62+
"@types/react-dom": "^18.0.8",
63+
"@umijs/fabric": "^3.0.0",
6464
"bluebird": "~3.7.2",
6565
"bootstrap": "^4.3.1",
6666
"cross-env": "^7.0.0",
67-
"dumi": "^1.1.0",
67+
"dumi": "^2.1.3",
6868
"enzyme": "^3.1.1",
6969
"enzyme-adapter-react-16": "^1.0.1",
7070
"enzyme-to-json": "^3.1.2",

src/Dialog/index.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,23 @@ export default function Dialog(props: IDialogPropTypes) {
5151
// ========================== Init ==========================
5252
const ariaId = useId();
5353

54+
function saveLastOutSideActiveElementRef() {
55+
if (!contains(wrapperRef.current, document.activeElement)) {
56+
lastOutSideActiveElementRef.current = document.activeElement as HTMLElement;
57+
}
58+
}
59+
60+
function focusDialogContent() {
61+
if (!contains(wrapperRef.current, document.activeElement)) {
62+
contentRef.current?.focus();
63+
}
64+
}
65+
5466
// ========================= Events =========================
5567
function onDialogVisibleChanged(newVisible: boolean) {
68+
// Try to focus
5669
if (newVisible) {
57-
// Try to focus
58-
if (!contains(wrapperRef.current, document.activeElement)) {
59-
lastOutSideActiveElementRef.current = document.activeElement as HTMLElement;
60-
contentRef.current?.focus();
61-
}
70+
focusDialogContent();
6271
} else {
6372
// Clean up scroll bar & focus back
6473
setAnimatedVisible(false);
@@ -131,6 +140,7 @@ export default function Dialog(props: IDialogPropTypes) {
131140
useEffect(() => {
132141
if (visible) {
133142
setAnimatedVisible(true);
143+
saveLastOutSideActiveElementRef();
134144
}
135145
}, [visible]);
136146

tests/index.spec.tsx

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable react/no-render-return-value, max-classes-per-file, func-names, no-console */
2-
import React, { cloneElement } from 'react';
2+
import React, { cloneElement, useEffect } from 'react';
33
import { act } from 'react-dom/test-utils';
44
import { render } from '@testing-library/react';
55
import type { ReactWrapper } from 'enzyme';
@@ -362,6 +362,60 @@ describe('dialog', () => {
362362
expect(modalRender.find('.rc-dialog-content').props().style.background).toEqual('#1890ff');
363363
});
364364

365+
describe('focusTriggerAfterClose', () => {
366+
it('should focus trigger after close dialog', () => {
367+
const Demo = () => {
368+
const [visible, setVisible] = React.useState(false);
369+
return (
370+
<>
371+
<button onClick={() => setVisible(true)}>trigger</button>
372+
<Dialog visible={visible} onClose={() => setVisible(false)}>
373+
content
374+
</Dialog>
375+
</>
376+
);
377+
};
378+
const wrapper = mount(<Demo />, { attachTo: document.body });
379+
const trigger = wrapper.find('button').at(0);
380+
(trigger.getDOMNode() as any).focus();
381+
trigger.simulate('click');
382+
jest.runAllTimers();
383+
const closeButton = wrapper.find('.rc-dialog-close');
384+
closeButton.simulate('click');
385+
jest.runAllTimers();
386+
expect(document.activeElement).toBe(trigger.getDOMNode());
387+
wrapper.unmount();
388+
});
389+
390+
it('should focus trigger after close dialog when contains focusable element', () => {
391+
const Demo = () => {
392+
const [visible, setVisible] = React.useState(false);
393+
const inputRef = React.useRef(null);
394+
useEffect(() => {
395+
inputRef.current?.focus();
396+
}, []);
397+
return (
398+
<>
399+
<button onClick={() => setVisible(true)}>trigger</button>
400+
<Dialog visible={visible} onClose={() => setVisible(false)}>
401+
<input ref={inputRef} />
402+
</Dialog>
403+
</>
404+
);
405+
};
406+
const wrapper = mount(<Demo />, { attachTo: document.body });
407+
const trigger = wrapper.find('button').at(0);
408+
(trigger.getDOMNode() as any).focus();
409+
trigger.simulate('click');
410+
jest.runAllTimers();
411+
const closeButton = wrapper.find('.rc-dialog-close');
412+
closeButton.simulate('click');
413+
jest.runAllTimers();
414+
expect(document.activeElement).toBe(trigger.getDOMNode());
415+
wrapper.unmount();
416+
});
417+
});
418+
365419
describe('size should work', () => {
366420
it('width', () => {
367421
const wrapper = mount(<Dialog visible width={1128} />);

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
"esModuleInterop": true,
1010
"paths": {
1111
"@/*": ["src/*"],
12-
"@@/*": ["src/.umi/*"],
12+
"@@/*": [".dumi/tmp/*"],
1313
"rc-dialog": ["src/index.ts"]
1414
}
15-
}
15+
},
16+
"include": [".dumi/**/*", ".dumirc.ts", "./src/**/*.ts", "./src/**/*.tsx", "./docs/**/*.tsx", "./tests/**/*.tsx"]
1617
}

0 commit comments

Comments
 (0)