diff --git a/CHANGELOG.md b/CHANGELOG.md index 85186709..503c80b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [2.13.1](https://github.com/streamich/libreact/compare/v2.13.0...v2.13.1) (2019-04-05) + + +### Bug Fixes + +* 🐛 call onElement from componentDidMount ([95fd86f](https://github.com/streamich/libreact/commit/95fd86f)) + # [2.13.0](https://github.com/streamich/libreact/compare/v2.12.2...v2.13.0) (2019-04-04) diff --git a/package.json b/package.json index 0cfc972e..606cea90 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libreact", - "version": "2.13.0", + "version": "2.13.1", "description": "React standard library", "main": "lib/index.js", "repository": { diff --git a/src/Modal/__story__/story.tsx b/src/Modal/__story__/story.tsx index e6e113cc..c55b8e87 100644 --- a/src/Modal/__story__/story.tsx +++ b/src/Modal/__story__/story.tsx @@ -11,7 +11,9 @@ storiesOf('UI/Modal', module) .add('Documentation', () => h(ShowDocs, {md: require('../../../docs/en/Modal.md')})) .add('Basic example', () =>
- + { + el.style.background = 'red'; + }}> foobar
diff --git a/src/Modal/index.ts b/src/Modal/index.ts index 3ca269da..7cbe97d5 100644 --- a/src/Modal/index.ts +++ b/src/Modal/index.ts @@ -48,52 +48,8 @@ export class Modal extends Component { componentDidMount () { on(document, 'keydown', this.onKey); - } - - componentWillUnmount () { - off(document, 'keydown', this.onKey); - - const siblings = Array.from(document.body.children); - - for (let i = 0; i < siblings.length; i++) { - const sibling = siblings[i] as HTMLElement; - const sib = sibling as any; - - if (sibling.hasAttribute(ignoreAttribute)) { - continue; - } - - if (sibling === this.el) { - continue; - } - - if (!sib.__libreact_lock) { - continue; - } - - if (sib.__libreact_lock.owner !== this) { - continue; - } - const lock = sib.__libreact_lock; - - sib.inert = lock.inert; - sibling.style.setProperty('pointer-events', lock.pointerEvents); - sibling.style.setProperty('user-select', lock.userSelect); - sibling.style.setProperty('filter', lock.filter || 'none'); - - sibling.removeAttribute('aria-hidden'); - delete sib.__libreact_lock; - } - - // Focus previously active element. - if (this.activeEl && (this.activeEl as any).focus) { - (this.activeEl as any).focus(); - } - } - - onElement = (el) => { - this.el = el; + const {el} = this; el.setAttribute('role', 'dialog'); el.classList.add('dialog'); @@ -146,6 +102,52 @@ export class Modal extends Component { } (this.props.onElement || noop)(el); + } + + componentWillUnmount () { + off(document, 'keydown', this.onKey); + + const siblings = Array.from(document.body.children); + + for (let i = 0; i < siblings.length; i++) { + const sibling = siblings[i] as HTMLElement; + const sib = sibling as any; + + if (sibling.hasAttribute(ignoreAttribute)) { + continue; + } + + if (sibling === this.el) { + continue; + } + + if (!sib.__libreact_lock) { + continue; + } + + if (sib.__libreact_lock.owner !== this) { + continue; + } + + const lock = sib.__libreact_lock; + + sib.inert = lock.inert; + sibling.style.setProperty('pointer-events', lock.pointerEvents); + sibling.style.setProperty('user-select', lock.userSelect); + sibling.style.setProperty('filter', lock.filter || 'none'); + + sibling.removeAttribute('aria-hidden'); + delete sib.__libreact_lock; + } + + // Focus previously active element. + if (this.activeEl && (this.activeEl as any).focus) { + (this.activeEl as any).focus(); + } + } + + onElement = (el) => { + this.el = el; }; onKey = (event) => { diff --git a/src/Overlay/index.ts b/src/Overlay/index.ts index f2970fde..0a4630f1 100644 --- a/src/Overlay/index.ts +++ b/src/Overlay/index.ts @@ -26,6 +26,7 @@ export class Overlay extends Component { }; componentDidMount () { + (this.props.onElement || noop)(this.el); document.body.classList.add(classNameBodyNoScroll); } @@ -60,8 +61,6 @@ export class Overlay extends Component { }, 35); on(el, 'click', this.onClick); - - (this.props.onElement || noop)(el); }; onClick = (event) => {