fix: add maskClosable is false ESC close
Showing 1 of 3 files from the diff.
Newly tracked file
components/drawer/index.tsx
changed.
Other files ignored by Codecov
components/drawer/index.en-US.md
has changed.
components/drawer/index.zh-CN.md
has changed.
@@ -1,5 +1,4 @@
Loading
1 | 1 | import * as React from 'react'; |
|
2 | - | import * as PropTypes from 'prop-types'; |
|
3 | 2 | import RcDrawer from 'rc-drawer'; |
|
4 | 3 | import createReactContext from '@ant-design/create-react-context'; |
|
5 | 4 | import warning from '../_util/warning'; |
@@ -10,7 +9,9 @@
Loading
10 | 9 | ||
11 | 10 | const DrawerContext = createReactContext<Drawer | null>(null); |
|
12 | 11 | ||
13 | - | type EventType = React.MouseEvent<HTMLDivElement> | React.MouseEvent<HTMLButtonElement>; |
|
12 | + | type EventType = |
|
13 | + | | React.KeyboardEvent<HTMLDivElement> |
|
14 | + | | React.MouseEvent<HTMLDivElement | HTMLButtonElement>; |
|
14 | 15 | ||
15 | 16 | type getContainerFunc = () => HTMLElement; |
|
16 | 17 |
@@ -39,6 +40,7 @@
Loading
39 | 40 | afterVisibleChange?: (visible: boolean) => void; |
|
40 | 41 | className?: string; |
|
41 | 42 | handler?: React.ReactNode; |
|
43 | + | keyboard?: boolean; |
|
42 | 44 | } |
|
43 | 45 | ||
44 | 46 | export interface IDrawerState { |
@@ -46,30 +48,6 @@
Loading
46 | 48 | } |
|
47 | 49 | ||
48 | 50 | class Drawer extends React.Component<DrawerProps & ConfigConsumerProps, IDrawerState> { |
|
49 | - | static propTypes = { |
|
50 | - | closable: PropTypes.bool, |
|
51 | - | destroyOnClose: PropTypes.bool, |
|
52 | - | getContainer: PropTypes.oneOfType([ |
|
53 | - | PropTypes.string, |
|
54 | - | PropTypes.object as PropTypes.Requireable<HTMLElement>, |
|
55 | - | PropTypes.func, |
|
56 | - | PropTypes.bool, |
|
57 | - | ]), |
|
58 | - | maskClosable: PropTypes.bool, |
|
59 | - | mask: PropTypes.bool, |
|
60 | - | maskStyle: PropTypes.object, |
|
61 | - | style: PropTypes.object, |
|
62 | - | title: PropTypes.node, |
|
63 | - | visible: PropTypes.bool, |
|
64 | - | width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), |
|
65 | - | zIndex: PropTypes.number, |
|
66 | - | prefixCls: PropTypes.string, |
|
67 | - | placement: PropTypes.oneOf(PlacementTypes), |
|
68 | - | onClose: PropTypes.func, |
|
69 | - | afterVisibleChange: PropTypes.func, |
|
70 | - | className: PropTypes.string, |
|
71 | - | }; |
|
72 | - | ||
73 | 51 | static defaultProps = { |
|
74 | 52 | width: 256, |
|
75 | 53 | height: 256, |
@@ -78,6 +56,7 @@
Loading
78 | 56 | maskClosable: true, |
|
79 | 57 | mask: true, |
|
80 | 58 | level: null, |
|
59 | + | keyboard: true, |
|
81 | 60 | }; |
|
82 | 61 | ||
83 | 62 | readonly state = { |
@@ -106,7 +85,7 @@
Loading
106 | 85 | }; |
|
107 | 86 | ||
108 | 87 | onMaskClick = (e: EventType) => { |
|
109 | - | if (!this.props.maskClosable) { |
|
88 | + | if (!this.props.maskClosable && !(e.nativeEvent instanceof KeyboardEvent)) { |
|
110 | 89 | return; |
|
111 | 90 | } |
|
112 | 91 | this.close(e); |
Files | Coverage |
---|---|
components | 96.01% |
Project Totals (263 files) | 96.01% |
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.