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

Trigger search addon from flyout input #108

Merged
merged 14 commits into from
Sep 7, 2023
Merged

Conversation

humitos
Copy link
Member

@humitos humitos commented Sep 5, 2023

This is an initial attempt to be able to render the readthedocs-search addon inside the readthedocs-flyout one.

I was able to:

  • include the readthedocs-search tag inside the flyout
  • connect the focusin event to the input from inside the flyout to call the search

Each time I click on the input from inside the flyout, it shows a log in the console (for debugging). However, due to some reason that I don't know yet, the readthedocs-search tag does not contains any HTML inside ito, so even when the modal is triggered, nothing is shown.

Related #90

This is an initial attempt to be able to render the `readthedocs-search` addon
inside the `readthedocs-flyout` one.

I was able to:

- include the `readthedocs-search` tag inside the flyout
- connect the `focusin` event to the input from inside the flyout to call the search

Each time I click on the input from inside the flyout, it shows a log in the
console (for debugging). However, due to some reason that I don't know yet, the
`readthedocs-search` tag does not contains any HTML inside ito, so even when the
modal is triggered, nothing is shown.

Related #90
@humitos humitos requested a review from a team as a code owner September 5, 2023 11:23
@humitos humitos requested a review from agjohnson September 5, 2023 11:23
@humitos
Copy link
Member Author

humitos commented Sep 5, 2023

I was able to make this work with a simpler approach. However, I would need some feedback here and maybe some javascript guidances since there some things that can be improved.

I want to read more documentation and play a little more with this pattern, but it seems it's the way to go.

Working example

Peek 2023-09-05 14-29

@agjohnson
Copy link
Contributor

Before we invest too heavily into using shadow DOM internals, I feel there are some easier solutions here that we can explore first:

Is there a reason we need to nest the web components in the first place? The search input is a modal that is separate from the flyout, and that users can implement in a doc native search input element. The flyout only requires a method to make the search modal visible.

If there is not a strong reason for this nesting, we only need a pattern for making the search web component modal visible from an element in the flyout web component.

The path forward I'm describing is:

This should remove the need for nesting, but also only requires that the search web component be defined once, globally, on the page.

@humitos
Copy link
Member Author

humitos commented Sep 5, 2023

This feedback is great, thanks! I will read a little more and explore your ideas.

@humitos
Copy link
Member Author

humitos commented Sep 5, 2023

Is there a reason we need to nest the web components in the first place? The search input is a modal that is separate from the flyout, and that users can implement in a doc native search input element. The flyout only requires a method to make the search modal visible.

Exactly. Originally, I tried to connect the input from inside the flyout to trigger the modal, but I wasn't able to. However, while I was doing the research to nest the search, I found how to connect the event with the input from inside the flyout -- but at that time I forgot that original idea 😅

However, I think this research will be useful for addons like docdiff (or similar ones) that has a UI (small checkbox for the docdiff currently). So, I guess that at some point we will need to nest them, maybe?

The path forward I'm describing is:

I will check this path 🚀

@agjohnson
Copy link
Contributor

So, I guess that at some point we will need to nest them, maybe?

Good question. Yeah, especially for docdiff that is still unknown. The docdiff web component is a bit unique, in that it has two components really -- the UI slider and the actual DOM manipulation part. I could see authors wanting to customize both, maybe independently even?

@humitos humitos changed the title Embeded webcomponents Trigger search addon from flyout input Sep 6, 2023
@humitos
Copy link
Member Author

humitos commented Sep 6, 2023

Man, I implemented your idea and it was pretty simple 🚀 . I think this is ready to get merged.

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.

💪 This is great! I'm glad this option worked out well for us, hopefully this pattern can work for docdiff and the flyout menu too.

src/search.js Outdated

// The "readthedocs-search-show" event is triggered by "readthedocs-flyout" input
document.addEventListener(
"readthedocs-search-show",
Copy link
Contributor

Choose a reason for hiding this comment

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

I could see us wanting to reuse this pattern a number of times perhaps. Maybe it makes sense to have event names defined as constants in a separate, events.js import?

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved this to an event.js file and import the event from the addons.

@humitos humitos merged commit a7a49eb into main Sep 7, 2023
@humitos humitos deleted the humitos/embed-web-components branch September 7, 2023 12:26
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