Skip to content

Commit 7723ff6

Browse files
committed
Scroll to top on new stage.
1 parent 3342064 commit 7723ff6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

frontend/src/components/participant_view/participant_view.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import './participant_help_panel';
2626
import './participant_nav';
2727

2828
import {MobxLitElement} from '@adobe/lit-mobx';
29+
import {reaction} from 'mobx';
2930
import {CSSResultGroup, html, nothing} from 'lit';
3031
import {customElement, property, state} from 'lit/decorators.js';
3132

@@ -64,6 +65,35 @@ export class ParticipantView extends MobxLitElement {
6465

6566
@state() isStartExperimentLoading = false;
6667

68+
private stageReactionDisposer?: () => void;
69+
70+
override connectedCallback() {
71+
super.connectedCallback();
72+
this.stageReactionDisposer = reaction(
73+
() => this.participantService.currentStageViewId,
74+
async () => {
75+
// Wait for Lit to re-render with the new stage component
76+
await this.updateComplete;
77+
const previewer = this.shadowRoot?.querySelector(
78+
'.participant-previewer',
79+
);
80+
previewer?.scrollTo(0, 0);
81+
// Stage components have their own overflow:auto on :host,
82+
// so scroll the stage element too.
83+
previewer
84+
?.querySelector(
85+
':scope > :not(participant-header):not(participant-nav)',
86+
)
87+
?.scrollTo(0, 0);
88+
},
89+
);
90+
}
91+
92+
override disconnectedCallback() {
93+
super.disconnectedCallback();
94+
this.stageReactionDisposer?.();
95+
}
96+
6797
override render() {
6898
const stageId = this.participantService.currentStageViewId;
6999
const stage = this.experimentService.getStage(stageId ?? '');

0 commit comments

Comments
 (0)