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

Allow scrollBehavior selectors to match ids with unescaped CSS special characters (feature request #3008) #3009

wants to merge 3 commits into
base: dev


Copy link

theprojectsomething commented Oct 24, 2019

As per the title and the original feature request #3008 this PR means a wider range of selectors are passed to document.getElementById, resulting in more straightforward use of scrollBehavior with e.g. to.hash

previously a scrollBehavior selector was only checked for ^#\d when determining whether to use getElementById or querySelector for matching; this would not work as intended for chained queries (e.g. `#9, .main`) or those with CSS special characters (e.g. `#one/two`).
@@ -121,14 +121,16 @@ function isNumber (v: any): boolean {
return typeof v === 'number'

const hashStartsWithNumberRE = /^#\d/
const selectorLooksLikeIdRE = /^#[^, ]+$/

This comment has been minimized.

Copy link

posva Oct 24, 2019


why any character but , and ?

This comment has been minimized.

Copy link

theprojectsomething Oct 24, 2019


@posva a , or suggests a complex selector (either nested or an OR). Technically an id selector could contain an , but the above provides the best balance of simplicity vs. coverage without breaking changes. Consider:

// Simple selector (passed to getElementById):

// Complex selector (passed to querySelector): 
#one .two
#one, .two
#one\,two // selects id="one,two"

Did you have any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.