-
Notifications
You must be signed in to change notification settings - Fork 483
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
fix(@clayui/tooltip): add polyfill for element.matches #3007
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit a16ff00:
|
Pull Request Test Coverage Report for Build 4511
💛 - Coveralls |
Tested on IE11, Chrome, and Firefox. Also passes SSR for gatsby build. Going to merge for todays release and if we make adjustments if needed. |
😢 I don't think Clay should be polyfilling anything — we shouldn't mutate global state, because we don't know if the environment we're going to be running in may provide or want to provide a polyfill of its own, and which order things will load in. In general, I think libraries are more broadly useful if they ask users to follow a BYOP (Bring Your Own Polyfill) pattern. Instead of a polyfill: if (typeof window !== 'undefined' && !Element.prototype.matches) {
Element.prototype.matches =
// @ts-ignore
Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector;
} A "ponyfill" would be better: function matches(element, selectorString) {
if (element.matches) {
return element.matches(selectorString);
} else if (element.msMatchesSelector) {
return element.msMatchesSelector(selectorString);
} else if (element.webkitMatchesSelector) {
return element.webkitMatchesSelector(selectorString);
} else {
return false;
}
} There is exactly one place where we use |
@wincent yeah you're totally right. I was thinking about it more last night after releasing and felt uneasy about it. I was concerned about mutating global state as well, but I figured that if we are already checking if it exists first, we should be relatively safe. But the caveat is that we can't dictate when this part of code is run, maybe someone mutates that state later. I like your solution though, I can add that and release again today to help mitigate any problems from my initial change. |
fixes #2998
This approach seemed the most straight forward. I had looked into via MDN and stackoverflow and this was the primary way recommended.
If you have any concerns, let me know!