Skip to content

Commit

Permalink
Merge pull request #10621 from notbakaneko/feature/discussions-unset-…
Browse files Browse the repository at this point in the history
…scroll-padding-extra-on-sticky-focus

Fix page scrolling when typing into new discussions text box
  • Loading branch information
nanaya authored Oct 6, 2023
2 parents a5beb1b + 3704f0e commit 79a23b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions resources/js/beatmap-discussions/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export class Main extends React.PureComponent
currentDiscussions: @currentDiscussions()
innerRef: @newDiscussionRef
mode: @state.currentMode
onFocus: @handleNewDiscussionFocus
pinned: @state.pinnedNewDiscussion
setPinned: @setPinnedNewDiscussion
stickTo: @modeSwitcherRef
Expand Down Expand Up @@ -357,6 +358,11 @@ export class Main extends React.PureComponent
@cache.groupedBeatmaps ?= BeatmapHelper.group _.values(@beatmaps())


handleNewDiscussionFocus: =>
# Bug with position: sticky and scroll-padding: https://bugs.chromium.org/p/chromium/issues/detail?id=1466472
document.documentElement.style.removeProperty '--scroll-padding-top-extra'


jumpToDiscussionByHash: =>
target = parseUrl(null, @state.beatmapset.discussions)

Expand Down
6 changes: 5 additions & 1 deletion resources/js/beatmap-discussions/new-discussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface Props {
currentDiscussions: CurrentDiscussions;
innerRef: React.RefObject<HTMLDivElement>;
mode: DiscussionMode;
onFocus?: () => void;
pinned: boolean;
setPinned: (flag: boolean) => void;
stickTo: React.RefObject<HTMLElement>;
Expand Down Expand Up @@ -186,7 +187,10 @@ export class NewDiscussion extends React.Component<Props> {
}
};

private readonly onFocus = () => this.setSticky(true);
private readonly onFocus = () => {
this.setSticky(true);
this.props.onFocus?.();
};

@action
private readonly post = (e: React.SyntheticEvent<HTMLElement>) => {
Expand Down
6 changes: 5 additions & 1 deletion resources/js/beatmap-discussions/new-review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface Props {
beatmapset: BeatmapsetExtendedJson;
currentBeatmap: BeatmapExtendedJson;
innerRef: React.RefObject<HTMLDivElement>;
onFocus?: () => void;
pinned?: boolean;
setPinned?: (sticky: boolean) => void;
stickTo?: React.RefObject<HTMLDivElement>;
Expand Down Expand Up @@ -109,7 +110,10 @@ export default class NewReview extends React.Component<Props> {
);
}

private readonly handleFocus = () => this.setSticky(true);
private readonly handleFocus = () => {
this.setSticky(true);
this.props.onFocus?.();
};

@action
private setSticky(sticky: boolean) {
Expand Down

0 comments on commit 79a23b8

Please sign in to comment.