How to make a custom search bar?

AI-generated summary

Custom Search Bar Discussion Summary

The discussion revolves around creating a custom search bar similar to the Search Banner Theme Component. pkundr wants to mirror the functionality of the default search bar to a custom <input type="text" /> element without using the existing theme component or plugin.

osioke suggests inspecting the code with a browser to determine the placement of the theme component and adjusting it accordingly. merefield recommends modifying the CSS to resolve appearance issues, while pkundr mentions that it’s not just a CSS issue, but also a matter of placement and HTML structure.

merefield provides an alternative solution using the Header Search Theme and suggests getting familiar with widget code if neither solution works.

I have been trying to build a custom search bar similar to the discourse-search-banner plugin. I don’t want to use that plugin as it interferes with the appearance of my theme.

How can I mirror that functionality to a <input type="text" /> of my choice?

I was looking at the source code of the plugin and tried to adapt it to just use my html element but was unable to figure it out. Any tips would be appreciated!

Would you mind linking that plugin here, I can’t seem to find it. Maybe also tag the plugin creator, they might have some ideas.

Are you talking about this Customization > Theme component?

Exactly! Sorry, my bad for not linking it I’ll make an edit

No worries, but that is a theme-component and not a plugin, so it changes a few things. Especially because theme-components work with client-side logic and plugins server-side logic. Or are you looking to make a plugin based of that theme-component?

Sorry for the late answer.

I don’t really care whether it ends up being a plugin or a theme component as long as I achieve the desired functionality. Basically what I need is to mirror the behavior of the default search (icon in top bar) to a text-input of my choice.

How do I go about this?

A lot of issues can be resolved in CSS.

What is stopping you from simply inspecting and modifying the CSS? That would be by far the quicker solution?

Worse case, fork the TC and edit your CSS?

It’s not really the CSS, more the placement and how it fits my HTML structure. If I can figure out how to modify where the component gets injected, I might have a solution. Can you point me in a direction?

With the theme component enabled on your site, inspect the code with your browser and see where it is placed. Adjust there in your browser to find somewhere more comfortable, and use that to update/edit a fork of the TC. That should work.

There’s also an off-the-shelf one for the Header:

If neither suits and CSS modifications are not enough, you are going to have to get dirty with widget code :).