You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently data-hotkey-scope only supports matching the (event.target i.e. the scope) as an id, this has a few limitations:
I may want to specify multiple elements as the scope for my hotkey.
I may need to specify an element rendered by a third part library as my scope and do not have access to set an id on that element. (This is my current actual issue).
Likely there are other uses-cases where an id doesn't work as a selector...
Suggestion
Add the ability to specify a class-name instead of an id for data-hotkey-scope.
Some possible API thoughts:
Support a 'mini selector syntax'
The API could be updated to take a # prefix (for id) or . prefix (for class name). We could continue to treat an un-prefixed value as an id:
<buttondata-hotkey-scope=".my-scope-class-name" /><buttondata-hotkey-scope="#my-scope-id" /><buttondata-hotkey-scope="my-scope-id" /><!-- legacy support -->
Add new data-attributes:
We could add data-hotkey-scope-class and data-hotkey-scope-id attributes. Again we could continue to treat the existing data-hotkey-scope as an id scope.
<buttondata-hotkey-scope-class="my-scope-class-name" /><buttondata-hotkey-scope-id="my-scope-id" /><buttondata-hotkey-scope="my-scope-id" /><!-- legacy support -->
Considerations
Why not allow full css-selector syntax?
I thought about the possibility of extending data-hotkey-scope to support full css selector syntax like data-hotkey-scope="div#parent > .target-element" ... but after talking this over with @keithamus we decided the complexity and likely performance cost of such an API would not be worth it given that id and class name already support many use-cases.
The text was updated successfully, but these errors were encountered:
theinterned
changed the title
a
Add support for class-name as data-hotkey-scopeNov 2, 2021
Problem
Currently
data-hotkey-scope
only supports matching the (event.target
i.e. the scope) as anid
, this has a few limitations:id
on that element. (This is my current actual issue).id
doesn't work as a selector...Suggestion
Add the ability to specify a class-name instead of an id for
data-hotkey-scope
.Some possible API thoughts:
Support a 'mini selector syntax'
The API could be updated to take a
#
prefix (forid
) or.
prefix (forclass
name). We could continue to treat an un-prefixed value as an id:Add new data-attributes:
We could add
data-hotkey-scope-class
anddata-hotkey-scope-id
attributes. Again we could continue to treat the existingdata-hotkey-scope
as an id scope.Considerations
Why not allow full css-selector syntax?
I thought about the possibility of extending
data-hotkey-scope
to support full css selector syntax likedata-hotkey-scope="div#parent > .target-element"
... but after talking this over with @keithamus we decided the complexity and likely performance cost of such an API would not be worth it given thatid
andclass
name already support many use-cases.The text was updated successfully, but these errors were encountered: