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

Option to specify search input id attribute #753

Open
marc-bouvier opened this issue Dec 13, 2024 · 0 comments
Open

Option to specify search input id attribute #753

marc-bouvier opened this issue Dec 13, 2024 · 0 comments

Comments

@marc-bouvier
Copy link

marc-bouvier commented Dec 13, 2024

Hello!, I would like to thank you for this tool. It was really easy for me to add and customize.

Related to #727

It could be great if we could specify the id attribute for the input generated for the search bar.
I could use it in my "Skip to content menu" to focus directly in the search input. More information about Skip to content : https://www.a11y-collective.com/blog/skip-to-main-content/

For now, I focus on the the search component's id , which require I press tab to focus the input element.

Screen Recording 2024-12-13 at 11 03 00(1)

  <nav class="header-skip-content">
        <ul>
            <li><a href="#content">Content</a></li>
-            <li><a href="#search" >Search</a></li>
+            <li><a href="#search-input" >Search</a></li>
            <li><a href="#menu">Menu</a></li>
        </ul>
    </nav>
    <script>
        window.addEventListener('DOMContentLoaded', (event) => {
            new PagefindUI({
            element: "#search", 
            showSubResults: true, 
            showImages: false,
+           inputId: "search-input"
            });
        });
    </script>

Would generate :

<div id="search">
    <div class="pagefind-ui  pagefind-ui--reset">
        <form class="pagefind-ui__form " role="search" aria-label="Search on this site"
              action="javascript:void(0);">
            <input 
+                   id="search-input"
                    class="pagefind-ui__search-input " 
                    type="text"
                    placeholder="Search" 
                    autocapitalize="none" 
                    enterkeyhint="search">
            <button class="pagefind-ui__search-clear  pagefind-ui__suppressed">Cleanup</button>
            <div class="pagefind-ui__drawer  pagefind-ui__hidden"></div>
        </form>
    </div>
</div>
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

No branches or pull requests

1 participant