Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally set attributes in EuiMutationObserver options #2180

Merged
merged 6 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
}

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