Skip to content

Commit

Permalink
feat: 🎸 don't blur elements with data-modal-ignore attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Apr 4, 2019
1 parent bbdbb22 commit 718c1df
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/en/Modal.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ Accepts all [`<Overlay>`](./Overlay.md) props in addition to:
- `close()` &mdash; method to calle `onClose` event.
- `idTitle` &mdash; id to set for aria title element.
- `idDescription` &mdash; id to set for aria description element.

Root nodes with `data-modal-ignore` attribute will not be dirty mutated (to create blur effect).
18 changes: 15 additions & 3 deletions src/Modal/__story__/story.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {createElement as h} from 'react';
import {createPortal} from 'react-dom';
import {storiesOf} from '@storybook/react';
import {action} from '@storybook/addon-actions';
import {Modal} from '..';
import {Toggle} from '../../Toggle';
import ShowDocs from '../../ShowDocs'
import {AfterTimeout} from '../../AfterTimeout';

storiesOf('UI/Modal', module)
.add('Documentation', () => h(ShowDocs, {md: require('../../../docs/en/Modal.md')}))
Expand All @@ -17,9 +19,19 @@ storiesOf('UI/Modal', module)
.add('Button underneath', () =>
<div>
<button onClick={() => alert('CLICKED')}>Click me!</button>
<Modal>
foobar
</Modal>
{createPortal(
<button onClick={() => alert('CLICKED')}>This should be blurred</button>,
document.body
)}
{createPortal(
<button data-modal-ignore="" onClick={() => alert('CLICKED')}>This element should not be blurred</button>,
document.body
)}
<AfterTimeout>
<Modal>
foobar
</Modal>
</AfterTimeout>
</div>
)
.add('With inputs', () =>
Expand Down
10 changes: 10 additions & 0 deletions src/Modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {Overlay, IOverlayProps} from '../Overlay';
let id = 0;
const ESC = 27;

const ignoreAttribute = 'data-modal-ignore';

export interface IModalProps extends IOverlayProps {
blur?: number;
dontLockFocus?: boolean;
Expand Down Expand Up @@ -57,6 +59,10 @@ export class Modal extends Component<IModalProps, IModalState> {
const sibling = siblings[i] as HTMLElement;
const sib = sibling as any;

if (sibling.hasAttribute(ignoreAttribute)) {
continue;
}

if (sibling === this.el) {
continue;
}
Expand Down Expand Up @@ -101,6 +107,10 @@ export class Modal extends Component<IModalProps, IModalState> {
for (let i = 0; i < siblings.length; i++) {
const sibling = siblings[i] as HTMLElement;

if (sibling.hasAttribute(ignoreAttribute)) {
continue;
}

if (sibling === el) {
continue;
}
Expand Down

1 comment on commit 718c1df

@streamich
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build version: 2.12.2-modal-2.169 🤞 modal-2 on Travis 🎉

Please sign in to comment.