Skip to content

Commit 718c1df

Browse files
committed
feat: 🎸 don't blur elements with data-modal-ignore attribute
1 parent bbdbb22 commit 718c1df

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

‎docs/en/Modal.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ Accepts all [`<Overlay>`](./Overlay.md) props in addition to:
5656
- `close()` &mdash; method to calle `onClose` event.
5757
- `idTitle` &mdash; id to set for aria title element.
5858
- `idDescription` &mdash; id to set for aria description element.
59+
60+
Root nodes with `data-modal-ignore` attribute will not be dirty mutated (to create blur effect).

‎src/Modal/__story__/story.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {createElement as h} from 'react';
2+
import {createPortal} from 'react-dom';
23
import {storiesOf} from '@storybook/react';
34
import {action} from '@storybook/addon-actions';
45
import {Modal} from '..';
56
import {Toggle} from '../../Toggle';
67
import ShowDocs from '../../ShowDocs'
8+
import {AfterTimeout} from '../../AfterTimeout';
79

810
storiesOf('UI/Modal', module)
911
.add('Documentation', () => h(ShowDocs, {md: require('../../../docs/en/Modal.md')}))
@@ -17,9 +19,19 @@ storiesOf('UI/Modal', module)
1719
.add('Button underneath', () =>
1820
<div>
1921
<button onClick={() => alert('CLICKED')}>Click me!</button>
20-
<Modal>
21-
foobar
22-
</Modal>
22+
{createPortal(
23+
<button onClick={() => alert('CLICKED')}>This should be blurred</button>,
24+
document.body
25+
)}
26+
{createPortal(
27+
<button data-modal-ignore="" onClick={() => alert('CLICKED')}>This element should not be blurred</button>,
28+
document.body
29+
)}
30+
<AfterTimeout>
31+
<Modal>
32+
foobar
33+
</Modal>
34+
</AfterTimeout>
2335
</div>
2436
)
2537
.add('With inputs', () =>

‎src/Modal/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {Overlay, IOverlayProps} from '../Overlay';
77
let id = 0;
88
const ESC = 27;
99

10+
const ignoreAttribute = 'data-modal-ignore';
11+
1012
export interface IModalProps extends IOverlayProps {
1113
blur?: number;
1214
dontLockFocus?: boolean;
@@ -57,6 +59,10 @@ export class Modal extends Component<IModalProps, IModalState> {
5759
const sibling = siblings[i] as HTMLElement;
5860
const sib = sibling as any;
5961

62+
if (sibling.hasAttribute(ignoreAttribute)) {
63+
continue;
64+
}
65+
6066
if (sibling === this.el) {
6167
continue;
6268
}
@@ -101,6 +107,10 @@ export class Modal extends Component<IModalProps, IModalState> {
101107
for (let i = 0; i < siblings.length; i++) {
102108
const sibling = siblings[i] as HTMLElement;
103109

110+
if (sibling.hasAttribute(ignoreAttribute)) {
111+
continue;
112+
}
113+
104114
if (sibling === el) {
105115
continue;
106116
}

0 commit comments

Comments
 (0)