How to customize your header search field to be centered?
Version 1.1 by Lucas Charpentier (Sereza7) on 2024/12/16
Some use cases of XWiki can benefit from a centered search field in the header. However, this does not benefit all instances, so this feature is not included in XWiki standard. Here is a short description on how to customize your own wiki to have this centered search.
- Edit the objects of the page XWiki.QuickSearchUIX to remove the "hiding input" logic
- Update the default template of the Search in the content of the UIExtensionClass object:
- Remove the globalsearch-close class from the form.
- Remove the aria-expanded='false' attribute from the button.
- Remove the disabled attribute from the input.
You should end up with something similar to:
<form class='navbar-form globalsearch form-inline' id='globalsearch' action='$searchURL' role='search'>
<label class='hidden' for='headerglobalsearchinput'>$services.localization.render('search')</label>
<button type='submit' class='btn' title="$services.localization.render('search')">$services.icon.renderHTML('search')</button>
<input type='text' name='text' placeholder="$services.localization.render('panels.search.inputText')" id='headerglobalsearchinput' />
</form>
- Replace the event listeners in the JavascriptExtension object.
- Update the search button click . You should simplify it to remove any call to the showSearchInput and hideSearchInput functions. The listener should look like this after your changes:
globalSearchButton.on('click', function() {return globalSearchInput.val().length > 0}); - Update the focusout event listener and replace the call to hideSearchInput with a simple fire of the event used to close the suggestion dropdown. The listener should look like this after your changes
- Update the search button click . You should simplify it to remove any call to the showSearchInput and hideSearchInput functions. The listener should look like this after your changes:
- Update the default template of the Search in the content of the UIExtensionClass object: