Input selection moves page focus to top of page #1544
Replies: 2 comments 3 replies
-
Interesting. I see the behavior in Safari and Firefox, but not in Chrome. It might have something to do with subtle differences in behavior for the |
Beta Was this translation helpful? Give feedback.
-
I believe the problem is triggered by the asynchronous nature of the The When you interact with the input, the associated generator yields a new value, and the Observable runtime then re-runs the code block referencing the input’s value. This creates a new There are a variety of ways to fix this issue… You could put some extra padding below the chart so that even when the charts briefly render as empty (due to asynchronous rendering via <div class="grid grid-cols-2" style="grid-auto-rows: 580px;">
<div class="card">
…
</div>
<div class="card">
…
</div>
</div> You’ll have to change the Another solution would be to avoid creating a new ```js
const clicks = view(Inputs.button());
```
```js
let currentChart;
let currentWidth;
let currentClicks;
function updateChart({width, clicks}) {
if (width === undefined) width = currentWidth; else currentWidth = width;
if (clicks === undefined) clicks = currentClicks; else currentClicks = clicks;
if (width === undefined || clicks === undefined) return;
const chart = Plot.frame().plot({title: `${clicks} clicks`, width});
currentChart?.replaceWith(chart);
return (currentChart = chart);
}
```
<div class="grid">
<div class="card">
${resize((width) => updateChart({width}))}
</div>
</div>
```js
updateChart({clicks});
``` I made a similar suggestion in #1567 (comment). Maybe we could add something special to Framework that detects when |
Beta Was this translation helpful? Give feedback.
-
I suspect this is just my lack of understanding - but whenever a user makes an input selection, the page resets to the top of the page.
An example is here: https://roux-ohdsi.observablehq.cloud/interactive-frailty-indices/
The lower two plost are nested within HTML cards rather than a js chunk, but I'm not sure if that's the issue:
Beta Was this translation helpful? Give feedback.
All reactions