Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

fix: Expanding Search (04.37): focus or keys coming into the field during Show me take it over instead of closing it around the focus; no tap highlight

matinde2b25075d42
diff --git a/animations/04-micro-interactions/expanding-search/README.md b/animations/04-micro-interactions/expanding-search/README.md
index fcccd750..2e9d9744 100644
--- a/animations/04-micro-interactions/expanding-search/README.md
+++ b/animations/04-micro-interactions/expanding-search/README.md
@@ -41,7 +41,7 @@ field.addEventListener('focusout', e => { // leaving it: the focus w
});
```
-The icon stays on top of the field. As the field opens, the icon's background turns see-through and its glass turns and fades away while the close button's cross turns in under it, so one seems to become the other; the links under the field fade out. While the field is open the icon lets presses through and is `inert`, so Tab cannot land on something hidden, and the field shows its focus with an inset ring while anything inside it has the focus. A press on the field around the text box (its glass or its edge) cancels the `mousedown` and puts the cursor back in the box, so it does not count as leaving. Show me opens the field and types into it without moving the real focus, so it never opens a phone's keyboard. Under reduced motion the transitions are switched off and the field opens and closes at once.
+The icon stays on top of the field. As the field opens, the icon's background turns see-through and its glass turns and fades away while the close button's cross turns in under it, so one seems to become the other; the links under the field fade out. While the field is open the icon lets presses through and is `inert`, so Tab cannot land on something hidden, and the field shows its focus with an inset ring while anything inside it has the focus. A press on the field around the text box (its glass or its edge) cancels the `mousedown` and puts the cursor back in the box, so it does not count as leaving. Show me opens the field and types into it without moving the real focus, so it never opens a phone's keyboard; a press or a Tab into the field while it runs hands the field to the visitor, still open. Under reduced motion the transitions are switched off and the field opens and closes at once.
## Key parameters
| Parameter | Default | Effect |
diff --git a/animations/04-micro-interactions/expanding-search/index.html b/animations/04-micro-interactions/expanding-search/index.html
index 7967c9db..bc7c5e7b 100644
--- a/animations/04-micro-interactions/expanding-search/index.html
+++ b/animations/04-micro-interactions/expanding-search/index.html
@@ -34,7 +34,7 @@
.links span{padding:0 10px;font-size:14px;line-height:44px;color:var(--ui-dim);white-space:nowrap}
.bar.open .links{opacity:0}
/* The icon sits at the end the field grows from: the right end (Left), or first, beside the logo (Right) */
- .sbtn{position:relative;z-index:1;order:2;margin-left:auto;flex:none;display:grid;place-items:center;width:44px;height:44px;border:0;border-radius:50%;background-color:var(--field);color:var(--ui-text);cursor:pointer;transition:background-color var(--dur) var(--ease)}
+ .sbtn{position:relative;z-index:1;order:2;margin-left:auto;flex:none;display:grid;place-items:center;width:44px;height:44px;border:0;border-radius:50%;background-color:var(--field);color:var(--ui-text);cursor:pointer;-webkit-tap-highlight-color:transparent;transition:background-color var(--dur) var(--ease)}
.to-right .sbtn{order:-1;margin:0 4px 0 0}
/* Open, the icon stays on top but turns see-through and lets presses through, while its glass turns away as the field's cross turns in */
.bar.open .sbtn{background-color:transparent;pointer-events:none}
@@ -54,7 +54,7 @@
.sfield input{flex:1;min-width:0;height:100%;border:0;background:none;color:var(--ui-text);font:inherit;font-size:15px;outline:none;-webkit-appearance:none;appearance:none}
.sfield input::placeholder{color:var(--ui-muted);opacity:1}
.sfield input::-webkit-search-cancel-button{display:none}
- .sclose{flex:none;display:grid;place-items:center;width:44px;height:44px;border:0;border-radius:50%;background:none;color:var(--ui-text);cursor:pointer;transition:background-color .15s}
+ .sclose{flex:none;display:grid;place-items:center;width:44px;height:44px;border:0;border-radius:50%;background:none;color:var(--ui-text);cursor:pointer;-webkit-tap-highlight-color:transparent;transition:background-color .15s}
.sclose svg{transition:opacity var(--dur) var(--ease),transform var(--dur) var(--ease)}
.bar:not(.open) .sclose svg{opacity:0;transform:rotate(-90deg) scale(.6)}
.sclose.hit{background:rgba(255,255,255,.12)}
@@ -247,15 +247,17 @@
later(()=>{input.value=''},2*dur,t+250);
});
$('btn-reset').addEventListener('click',()=>{stopRun();toRest()});
- // The visitor pressed, typed, scrolled or touched inside the stage: the run stops. A press on the field, open or still closing,
- // takes it over (it stays open with the run's text, and the press puts the focus in it); any other input closes it and empties it.
+ // The visitor pressed, typed, scrolled or touched inside the stage: the run stops. A press on the field, open or still closing, or
+ // input while the focus is in it takes it over (it stays open with the run's text and the focus); any other input closes and empties it.
stage.addEventListener('pointerdown',e=>{downInField=field.contains(e.target)},true);
document.addEventListener('hb:input',e=>{
if(!running())return;
stopRun();
- if(e.detail.type==='pointerdown'&&downInField){bar.classList.remove('is-demo');open(false);return}
+ if((e.detail.type==='pointerdown'&&downInField)||field.contains(document.activeElement)){bar.classList.remove('is-demo');open(false);return}
close(false);input.value='';
});
+ // Focus that comes into the field while the run goes on (Shift+Tab from Show me lands on its close button) takes it over the same way
+ field.addEventListener('focusin',()=>{if(running()){stopRun();bar.classList.remove('is-demo');open(false)}});
function choices(id,pick){
const buttons=document.querySelectorAll('#'+id+' button');