-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve fullscreen UX (keep focus on reset, fix reset position, blur …
…on Esc) The demo has a new "fullscreen" version where, if there is any focus-within inside the typesense-minibar element, it will make the element cover the entire viewport. In doing this, a few issues were uncovered: * When pressing the "reset" button, the fullscreen mode unexpectedly exited itself from time "mousedown" happens, even before it is let go and turned into a click. This is because the reset icon is an unfocusable SVG, so by default as soon as mousedown happens, the focus is no longer in the input field, and since the SVG isn't focussable, the focus returns briefly to the `<main>` or `<body>`. In the default way the element works (i.e. not fullscreen), this is fairly harmless because by the time the mouseup happens, the cursor is still on the reset button, "click" fires on the icon, our event handler is called, and our callback does `input.focus()` to bring focus back. The only downside so far was a brief flashing of the non-focus styles for the input field between mouse-down and mouse-up. In the fullscreen demo, after mouse-down on the reset icon, this moved focus to the main element, thus defocusing the form, thus the fullscreen styles stop applying, thus the whole form is now in a different position in the viewport, thus when you mouse-up, the click doesn't happen on the icon, it happens on a blank spot in the page. This also means our event handler never fired, so the input field remained non-empty, the listbox remained open, and focus does not return. Fix this by setting tabindex="-1" on the reset icon. This means it remains outside the sequential keyboard navigation (same as before), but when you click it, it is capable of receiving focus. This means `:focus-within` remains applying, the fullscreen styles remain active, and so when you mouse-up, the cursor is still on the same icon, so a "click" will go it it, and our event handler does what it should (empty input field, close listbox, move focus to input element). * The magnify icon is correctly positioned as "half of the input field from the top" relative to the `<form>`, which works regarldess of how tall the parent element is. The reset button, however, was positioned "in the vertical middle" of the parent. This is identical in the common case since the `<form>` element is exactly as tall as just the input element, there is nothing else there. But, in this fullscreen mode, the element becomes much taller. Fix the CSS of the reset button to calculate its position from the top down, without using any "50% - stuff" calculation. * When pressing Esc, we previously only closed the listbox results, but kept focus in the input field. This was fairly harmless, but for the fullscreen case, this means it is impossible to get out of it with keyboard only, since the entire page is covered. The only other way to close the fullscreen mode was to click somewhere outside the input field. Now Esc works as well, by explicitly de-focussing (blur) the input field, thus returning focus back to where it was (probably the `<body>` or `<main>` element).
- Loading branch information
Showing
8 changed files
with
92 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
<body> | ||
<header> | ||
<h2>DocSearch.js v3</h2> | ||
<div id="searchbar"> | ||
<div id="searchbar"></div> | ||
</header> | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters