How to make a custom search bar?

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!

1 Like

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.

2 Likes

Are you talking about this #theme-component?

2 Likes

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

1 Like

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?

1 Like

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?

1 Like

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 :).

1 Like