forked from Furumi/furumi-web
feat: expand mobile search while focused
This commit is contained in:
1 parent
ea3a95da42
commit
f833eaefec
3 files changed
+65
-3
No files matched your search
@@ -321,20 +321,28 @@
|
||||
<a x-show="$store.user.accessStatus === 'anonymous'" href="/login?next=/share/{{ share_token }}">{{ t.guest_login }}</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="search-bar">
|
||||
<div class="search-bar"
|
||||
x-data="{ expanded:false, left:0, right:0, measure() { const bar=$el.getBoundingClientRect(); const panel=$el.closest('.content-topbar').getBoundingClientRect(); this.left=Math.max(0,bar.left-panel.left); this.right=Math.max(0,panel.right-bar.right); } }"
|
||||
:class="{ 'search-expanded':expanded }"
|
||||
:style="{ '--search-expand-left':left+'px', '--search-expand-right':right+'px' }"
|
||||
@focusin="measure(); expanded=true; $store.user.menuOpen=false"
|
||||
@focusout="if (!$el.contains($event.relatedTarget)) expanded=false"
|
||||
@resize.window="measure()">
|
||||
<div class="search-field">
|
||||
<span class="search-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg></span>
|
||||
<input id="search-input" type="text" placeholder="{{ t.player_search_placeholder }}"
|
||||
<input id="search-input" x-ref="searchInput" type="text" placeholder="{{ t.player_search_placeholder }}"
|
||||
x-model="$store.library.searchQuery"
|
||||
@input.debounce.300ms="$store.library.search($store.library.searchQuery)"
|
||||
@keydown.escape="$store.library.clearSearch(); $el.blur()">
|
||||
<template x-if="$store.library.searchQuery">
|
||||
<button class="search-clear" @click="$store.library.clearSearch()">
|
||||
<button class="search-clear" @pointerdown.prevent @click="$store.library.clearSearch(); $refs.searchInput.focus()">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
</button>
|
||||
</template>
|
||||
<template x-if="!$store.library.searchQuery">
|
||||
<span class="search-shortcut">Ctrl+K</span>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
{% if downloads_enabled %}
|
||||
<button class="torrent-import-btn"
|
||||
|
||||
@@ -2488,6 +2488,18 @@ button.user-stat:hover {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.search-field {position:relative;left:0;width:100%}
|
||||
|
||||
@media (max-width:560px) {
|
||||
.content-topbar div.search-bar {flex:1 1 0;z-index:5}
|
||||
.search-field {transition:left 160ms ease-out,width 160ms ease-out}
|
||||
.search-expanded .search-field {
|
||||
left:calc(-1 * var(--search-expand-left,0px));
|
||||
width:calc(100% + var(--search-expand-left,0px) + var(--search-expand-right,0px));
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion:reduce) {.search-field {transition:none}}
|
||||
|
||||
.version-chip {
|
||||
flex: 0 0 auto;
|
||||
color: var(--text-subdued);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
const {chromium}=require(process.env.PLAYWRIGHT_MODULE||'playwright');
|
||||
const fs=require('node:fs'),assert=require('node:assert/strict');
|
||||
const html=fs.readFileSync('target/podcast-player-fixture.html','utf8'),alpine=fs.readFileSync('target/podcast-alpine.min.js','utf8');
|
||||
const near=(a,b,message)=>assert.ok(Math.abs(a-b)<1,`${message}: ${a} vs ${b}`);
|
||||
(async()=>{
|
||||
const browser=await chromium.launch({headless:true,...(process.env.CHROME_PATH?{executablePath:process.env.CHROME_PATH}:{})});
|
||||
try{
|
||||
for(const width of [320,390,560,820,1440]){
|
||||
const page=await browser.newPage({viewport:{width,height:900}}),errors=[];page.on('pageerror',e=>errors.push(e.message));
|
||||
await page.route('**/*',route=>{
|
||||
const u=new URL(route.request().url());
|
||||
if(u.hostname==='search.test'&&u.pathname==='/')return route.fulfill({contentType:'text/html',body:html});
|
||||
if(u.hostname==='cdn.jsdelivr.net'&&u.pathname.includes('alpine'))return route.fulfill({contentType:'application/javascript',body:alpine});
|
||||
if(u.pathname==='/api/player/artists')return route.fulfill({json:{items:[],total:0,has_more:false}});
|
||||
if(u.pathname==='/api/player/search')return route.fulfill({json:{artists:[],releases:[],tracks:[],podcasts:[]}});
|
||||
return route.fulfill({json:[]});
|
||||
});
|
||||
await page.goto('http://search.test/');await page.waitForFunction(()=>window.Alpine?.store('library'));
|
||||
const input=page.locator('#search-input'),panel=page.locator('.content-topbar');
|
||||
const original=await input.boundingBox(),panelBefore=await panel.boundingBox(),buttonBefore=await page.locator('.torrent-import-btn').boundingBox();
|
||||
await input.focus();
|
||||
if(width<=560){
|
||||
await page.waitForFunction(()=>{const input=document.querySelector('#search-input').getBoundingClientRect(),panel=document.querySelector('.content-topbar').getBoundingClientRect();return Math.abs(input.width-panel.width)<1;});
|
||||
const expanded=await input.boundingBox();near(expanded.x,panelBefore.x,'expanded left edge');near(expanded.width,panelBefore.width,'expanded width');
|
||||
assert.ok(expanded.width>original.width+80,'search gains the space of neighboring controls');
|
||||
const topmost=await page.evaluate(()=>{const panel=document.querySelector('.content-topbar').getBoundingClientRect();return document.elementFromPoint(panel.right-10,panel.top+panel.height/2)?.id;});
|
||||
assert.equal(topmost,'search-input','search overlays account and download controls');
|
||||
const duration=await page.locator('.search-field').evaluate(el=>parseFloat(getComputedStyle(el).transitionDuration));assert.ok(duration>0&&duration<=0.2);
|
||||
if(buttonBefore){const after=await page.locator('.torrent-import-btn').boundingBox();near(after.x,buttonBefore.x,'neighboring controls remain in place');}
|
||||
await input.fill('A long search query');await page.locator('.search-clear').click();
|
||||
assert.equal(await input.inputValue(),'');assert.equal(await input.evaluate(el=>document.activeElement===el),true,'clear retains input focus');
|
||||
await page.screenshot({path:`target/mobile-search-focused-${width}.png`});
|
||||
await input.evaluate(el=>el.blur());
|
||||
await page.waitForFunction(expected=>Math.abs(document.querySelector('#search-input').getBoundingClientRect().width-expected)<1,original.width);
|
||||
near((await input.boundingBox()).x,original.x,'blur restores position');near((await panel.boundingBox()).height,panelBefore.height,'header height remains stable');
|
||||
await page.emulateMedia({reducedMotion:'reduce'});assert.equal(await page.locator('.search-field').evaluate(el=>getComputedStyle(el).transitionDuration),'0s');
|
||||
}else{near((await input.boundingBox()).width,original.width,'larger screens retain normal search width');}
|
||||
assert.deepEqual(errors,[]);await page.close();
|
||||
}
|
||||
console.log('Mobile search expansion, overlay, clear, blur and reduced-motion checks passed.');
|
||||
}finally{await browser.close();}
|
||||
})().catch(e=>{console.error(e);process.exitCode=1;});
|
||||
Reference in new issue
Block a user