techfreakworm commited on
Commit
6bd9581
·
unverified ·
1 Parent(s): 00814ae

fix(ui): drawer toggle via JS class-flip — Gradio CSS scope breaks :has()

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -147,7 +147,6 @@ _CUSTOM_CSS = """
147
  border-bottom: 1px solid #262C35;
148
  background: #12161B;
149
  }
150
- .aio-ham-toggle { display: none; } /* hidden checkbox drives drawer state */
151
  .aio-ham-label {
152
  display: none;
153
  width: 32px; height: 32px;
@@ -244,10 +243,11 @@ _CUSTOM_CSS = """
244
  max-width: 80vw;
245
  overflow: hidden;
246
  }
247
- /* checkbox at #aio-ham-toggle is the only sibling pattern Gradio
248
- lets us reach without JS when checked, slide drawer in. */
249
- body:has(#aio-ham-toggle:checked) .aio-drawer { left: 0; }
250
- body:has(#aio-ham-toggle:checked) .aio-shell::before {
 
251
  content: ""; position: fixed; inset: 0;
252
  background: rgba(0,0,0,0.55); z-index: 9;
253
  }
@@ -310,12 +310,14 @@ _TOPAZ_THEME = gr.themes.Base(
310
 
311
  def build_app() -> gr.Blocks:
312
  with gr.Blocks(theme=_TOPAZ_THEME, title="LTX 2.3 Studio", css=_CUSTOM_CSS) as app:
313
- # Header: hamburger checkbox (drives drawer via :checked + :has() in CSS),
314
- # title, current-mode tag.
315
  gr.HTML(
316
  '<div class="aio-header">'
317
- ' <input type="checkbox" id="aio-ham-toggle" class="aio-ham-toggle">'
318
- ' <label for="aio-ham-toggle" class="aio-ham-label">≡</label>'
 
 
319
  ' <span class="aio-title">LTX 2.3 <span class="accent">Studio</span></span>'
320
  ' <span class="aio-mode-tag" id="aio-mode-tag">T2V</span>'
321
  '</div>'
@@ -376,8 +378,7 @@ def build_app() -> gr.Blocks:
376
  f"const el = document.getElementById('aio-mode-tag'); "
377
  f"if (el) el.textContent = {tag!r}; "
378
  f"if (window.matchMedia('(max-width: 1023px)').matches) {{ "
379
- f" const t = document.getElementById('aio-ham-toggle'); "
380
- f" if (t) t.checked = false; "
381
  f"}} return []; }}",
382
  )
383
 
 
147
  border-bottom: 1px solid #262C35;
148
  background: #12161B;
149
  }
 
150
  .aio-ham-label {
151
  display: none;
152
  width: 32px; height: 32px;
 
243
  max-width: 80vw;
244
  overflow: hidden;
245
  }
246
+ /* `.aio-shell.drawer-open` is toggled by the hamburger's inline JS.
247
+ `body:has(:checked)` would be cleaner but Gradio prefixes user CSS
248
+ with `.gradio-container .contain `, breaking ancestor selectors. */
249
+ .aio-shell.drawer-open .aio-drawer { left: 0; }
250
+ .aio-shell.drawer-open::before {
251
  content: ""; position: fixed; inset: 0;
252
  background: rgba(0,0,0,0.55); z-index: 9;
253
  }
 
310
 
311
  def build_app() -> gr.Blocks:
312
  with gr.Blocks(theme=_TOPAZ_THEME, title="LTX 2.3 Studio", css=_CUSTOM_CSS) as app:
313
+ # Header: hamburger button toggles `.drawer-open` class on `.aio-shell`
314
+ # via inline JS (Gradio prefixes user CSS so `body:has(:checked)` breaks).
315
  gr.HTML(
316
  '<div class="aio-header">'
317
+ ' <button type="button" class="aio-ham-label" '
318
+ ' onclick="document.querySelector(\'.aio-shell\')'
319
+ '?.classList.toggle(\'drawer-open\')" '
320
+ ' aria-label="Toggle navigation">≡</button>'
321
  ' <span class="aio-title">LTX 2.3 <span class="accent">Studio</span></span>'
322
  ' <span class="aio-mode-tag" id="aio-mode-tag">T2V</span>'
323
  '</div>'
 
378
  f"const el = document.getElementById('aio-mode-tag'); "
379
  f"if (el) el.textContent = {tag!r}; "
380
  f"if (window.matchMedia('(max-width: 1023px)').matches) {{ "
381
+ f" document.querySelector('.aio-shell')?.classList.remove('drawer-open'); "
 
382
  f"}} return []; }}",
383
  )
384