Skip to content

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

Merged
merged 4 commits into from
Apr 27, 2023

Conversation

humitos
Copy link
Member

@humitos humitos commented Apr 20, 2023

Define two new attributes show-modal-selector and show-modal-event to allow the user defining which HTML element will show the modal.

Peek 2023-04-20 09-45

In this example, when clicking on the input it will show the modal.

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.
@humitos humitos requested a review from a team as a code owner April 20, 2023 15:43
@humitos humitos requested a review from agjohnson April 20, 2023 15:43
@humitos
Copy link
Member Author

humitos commented Apr 20, 2023

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.

Copy link
Contributor

@agjohnson agjohnson left a 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) => {
Copy link
Contributor

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()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.

@humitos humitos requested a review from agjohnson April 25, 2023 21:31
@@ -64,7 +66,9 @@ export class SearchElement extends LitElement {
this.currentQueryRequest = null;
this.defaultFilter = null;
this.filters = [];
this.showModalKeycode = 191;
this.triggerKeycode = 191;
Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member Author

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? 🤔

Copy link
Contributor

@agjohnson agjohnson Apr 27, 2023

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.

@humitos
Copy link
Member Author

humitos commented Apr 27, 2023

I think this is ready to merge. I asked a question, but it can probably be achieved in a different PR. Let me know.

Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, looks good!

@humitos humitos merged commit 2ec01e9 into main Apr 27, 2023
@humitos humitos deleted the humitos/search-user-trigger branch April 27, 2023 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants