lhoestq HF staff commited on
Commit
2f04b21
·
1 Parent(s): d73459b

add scroll to top

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -353,14 +353,25 @@ with gr.Blocks(css=css) as demo:
353
 
354
  show_dataset_inputs = [search_bar, *buttons]
355
  show_dataset_outputs = [app_state, search_page, dataset_page, dataset_title, dataset_content, dataset_share_textbox]
 
 
 
 
 
 
 
 
 
 
 
356
 
357
  def show_dataset_from_button(search_query, *buttons_values, i):
358
  dataset_name, tags = buttons_values[2 * i : 2 * i + 2]
359
  yield from _show_dataset(search_query, dataset_name, tags)
360
 
361
  for i, (dataset_name_button, tags_button) in enumerate(batched(buttons, 2)):
362
- dataset_name_button.click(partial(show_dataset_from_button, i=i), inputs=show_dataset_inputs, outputs=show_dataset_outputs)
363
- tags_button.click(partial(show_dataset_from_button, i=i), inputs=show_dataset_inputs, outputs=show_dataset_outputs)
364
 
365
 
366
  @back_button.click(outputs=[search_page, dataset_page])
 
353
 
354
  show_dataset_inputs = [search_bar, *buttons]
355
  show_dataset_outputs = [app_state, search_page, dataset_page, dataset_title, dataset_content, dataset_share_textbox]
356
+ scroll_to_top_js = """
357
+ function (...args) {
358
+ console.log(args);
359
+ if ('parentIFrame' in window) {
360
+ window.parentIFrame.scrollTo({top: 0, behavior:'smooth'});
361
+ } else {
362
+ window.scrollTo({ top: 0 });
363
+ }
364
+ return args;
365
+ }
366
+ """.replace("len(show_dataset_inputs)", str(len(show_dataset_inputs)))
367
 
368
  def show_dataset_from_button(search_query, *buttons_values, i):
369
  dataset_name, tags = buttons_values[2 * i : 2 * i + 2]
370
  yield from _show_dataset(search_query, dataset_name, tags)
371
 
372
  for i, (dataset_name_button, tags_button) in enumerate(batched(buttons, 2)):
373
+ dataset_name_button.click(partial(show_dataset_from_button, i=i), inputs=show_dataset_inputs, outputs=show_dataset_outputs, js=scroll_to_top_js)
374
+ tags_button.click(partial(show_dataset_from_button, i=i), inputs=show_dataset_inputs, outputs=show_dataset_outputs, js=scroll_to_top_js)
375
 
376
 
377
  @back_button.click(outputs=[search_page, dataset_page])