Skip to content

Commit

Permalink
Conditionally set attributes in EuiMutationObserver options (#2180)
Browse files Browse the repository at this point in the history
* add attributes option

* CL

* use mutationObserver as the keeper of spec logic

* update CL

* clone
  • Loading branch information
thompsongl authored Jul 31, 2019
1 parent fbe7f1b commit 09f2b5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `13.1.0`.
**Bug fixes**

- Fixed `EuiMutationObserver` errors in IE11 by conditionally setting the `attributes` observer option according to the new spec ([#2180](https://github.com/elastic/eui/pull/2180))

## [`13.1.0`](https://github.com/elastic/eui/tree/v13.1.0)

Expand Down
17 changes: 16 additions & 1 deletion src/components/observer/mutation_observer/mutation_observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@ export class EuiMutationObserver extends EuiObserver<Props> {
name = 'EuiMutationObserver';

beginObserve = () => {
// IE11 and the MutationObserver polyfill used in Kibana (for Jest) implement
// an older spec in which specifying `attributeOldValue` or `attributeFilter`
// without specifying `attributes` results in a `SyntaxError`.
// The following logic patches the newer spec in which `attributes: true` can be
// implied when appropriate (`attributeOldValue` or `attributeFilter` is specified).
const observerOptions: MutationObserverInit = {
...this.props.observerOptions,
};
const needsAttributes =
observerOptions.hasOwnProperty('attributeOldValue') ||
observerOptions.hasOwnProperty('attributeFilter');
if (needsAttributes && !observerOptions.hasOwnProperty('attributes')) {
observerOptions.attributes = true;
}

this.observer = new MutationObserver(this.props.onMutation);
this.observer.observe(this.childNode!, this.props.observerOptions);
this.observer.observe(this.childNode!, observerOptions);
};
}

0 comments on commit 09f2b5b

Please sign in to comment.