-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[core] Handle selection edge case #7350
Conversation
These are the results for the performance tests:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really a core
PR ?
I think that it has barely any impact, so most people wouldn't care. |
Signed-off-by: Olivier Tassinari <olivier.tassinari@gmail.com>
@@ -26,15 +26,15 @@ function writeToClipboardPolyfill(data: string) { | |||
} | |||
|
|||
function hasNativeSelection(element: HTMLInputElement) { | |||
if (window.getSelection()?.toString() !== '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cherniavskii I think that this wasn't exactly correct. Per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
If the object accessed or function called is undefined or null, it returns undefined instead of throwing an error.
So when the selection returns null, the chaining returns undefined
which we then compare to ''
. it's different, so hasNativeSelection
say there is a selection. But there is no selection in this case, in theory, per https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection.
When called on an <iframe> that is not displayed (e.g., where display: none is set) Firefox will return null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
Per https://github.com/mui/material-ui/pull/35670/files#r1059417694, this might be better