-
Notifications
You must be signed in to change notification settings - Fork 17
Search: define which element & event shows the modal #58
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
Conversation
Define two new attributes `show-modal-selector` and `show-modal-event` to allow the user defining which HTML element will show the modal. In this example, when clicking on the `input` it will show the modal.
This is another example towards the definition of the pattern we want to implement. It answers the question what's the selector for the search-as-you-type be triggered? from #13 I'm not 100 sure about this pattern yet, but I opened this PR as an example and to start receiving feedback. However, I think it's simple enough and easy to customize and maintain, I think. |
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 think this is an good pattern for us to have, though I can also see how more advanced maintainers will want something more direct, like calling a JS method directly. That can be a later addition, this pattern will work for the majority of users.
@@ -490,13 +494,28 @@ export class SearchElement extends LitElement { | |||
} | |||
}; | |||
|
|||
_handleShowModalUser = (e) => { |
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.
Any reason this isn't a normal class method instead of an anonymous function? It seems to be used as a method, given this.showModal()
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.
Yes. There is a reason for this,
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.
Gotcha, that makes sense. I was going to suggest a static method, but I think in that scope this
refers to the class itself.
Format the code before pushing.
@@ -64,7 +66,9 @@ export class SearchElement extends LitElement { | |||
this.currentQueryRequest = null; | |||
this.defaultFilter = null; | |||
this.filters = []; | |||
this.showModalKeycode = 191; | |||
this.triggerKeycode = 191; |
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.
@agjohnson should we have a trigger-modifier
here or similar? See #57
How can we make people to use Ctrl + K
for example to show the search?
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 question. I haven't done this, but it looks like we can get the modifier state from the keydown event passed into our event handler function.
I will say that we should be careful with defaults here though. It's easy to override native key bindings when working with modifier key presses.
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 fine to add a trigger-modifier-keycode
attribute for this? 🤔
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.
Yeah, something like that, though I don't think keycode
is the most correct. I believe this is the KeyboardEvent method you'd want to use:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/getModifierState
So, more like <readthedocs-search trigger-key-modifier="control">
or something.
I think this is ready to merge. I asked a question, but it can probably be achieved in a different PR. Let me know. |
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.
Yup, looks good!
Define two new attributes
show-modal-selector
andshow-modal-event
to allow the user defining which HTML element will show the modal.In this example, when clicking on the
input
it will show the modal.