-
Notifications
You must be signed in to change notification settings - Fork 65
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/accordion highlight #3182
Fix/accordion highlight #3182
Conversation
🤖 Pull request artifacts
|
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.
Good solution, just a suggestion for improvement.
// Prevent text selection while animating | ||
const content = el.querySelector( '.stk-block-accordion__content' ) | ||
content.style.userSelect = 'none' |
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.
It seems that doing this on the content would still make the text highlight. I would recommend doing this on the element itself to prevent this:
// Prevent text selection while animating | |
const content = el.querySelector( '.stk-block-accordion__content' ) | |
content.style.userSelect = 'none' | |
// Prevent text selection while animating | |
el.style.userSelect = 'none' |
if ( window.getSelection ) { | ||
// eslint-disable-next-line @wordpress/no-global-get-selection | ||
const selection = window.getSelection() | ||
if ( selection.removeAllRanges ) { | ||
selection.removeAllRanges() | ||
} | ||
} else if ( document.selection ) { | ||
// For older IE browsers | ||
document.selection.empty() | ||
} | ||
content.style.userSelect = 'auto' |
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.
I see that you are clearing the selection because the userSelect
above was not taking full effect and you can still highlight text when opening an accordion. Applying the style directly on the element fixes things, and now you do not need all of the selection removal code.
Also, to me, if the fix only partially works and you needed to add some selection removal code to compensate is an indicator that there should be a cleaner solution 👍
if ( window.getSelection ) { | |
// eslint-disable-next-line @wordpress/no-global-get-selection | |
const selection = window.getSelection() | |
if ( selection.removeAllRanges ) { | |
selection.removeAllRanges() | |
} | |
} else if ( document.selection ) { | |
// For older IE browsers | |
document.selection.empty() | |
} | |
content.style.userSelect = 'auto' | |
el.style.userSelect = 'auto' |
fixes #3096