Skip to content

Commit

Permalink
Undo Page changes to see what test:build does
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyEJohnson committed Nov 14, 2024
1 parent 47251c8 commit a39ed17
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/app/content/components/Page/PageComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export default class PageComponent extends Component<PagePropTypes> {
// Wait for the mathjax promise set by postProcess from previous or current componentDidUpdate call.
await Promise.all(this.processing);

this.container.current?.focus();
this.scrollToTopOrHashManager(prevProps.scrollToTopOrHash, this.props.scrollToTopOrHash);

const searchHighlightsChanged = !isEqual(
Expand Down
4 changes: 0 additions & 4 deletions src/app/content/components/Page/PageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export default styled(MainContent)`
${contentTextStyle}
overflow: visible;
:focus-visible {
outline: none;
}
@media screen {
flex: 1;
display: flex;
Expand Down
16 changes: 11 additions & 5 deletions src/app/content/components/Page/scrollToTopOrHashManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HTMLElement } from '@openstax/types/lib.dom';
import { scrollTo } from '../../../domUtils';
import * as selectNavigation from '../../../navigation/selectors';
import { AppState } from '../../../types';
import { assertWindow, memoizeStateToProps } from '../../../utils';
import { assertWindow, memoizeStateToProps, resetTabIndex } from '../../../utils';
import { isSearchScrollTarget } from '../../search/guards';
import { selectedResult } from '../../search/selectors';
import * as select from '../../selectors';
Expand All @@ -26,14 +26,20 @@ const scrollToTarget = (container: HTMLElement | null, hash: string) => {
}
};

const scrollToTargetOrTop = (container: HTMLElement | null, hash: string, previous: boolean) => {
const scrollToTargetOrTop = (container: HTMLElement | null, hash: string) => {
if (getScrollTarget(container, hash)) {
scrollToTarget(container, hash);
} else if (previous) {
assertWindow().scrollTo(0, 0);
} else {
scrollToTop();
}
};

const scrollToTop = () => {
const window = assertWindow();
resetTabIndex(window.document);
window.scrollTo(0, 0);
};

const getScrollTarget = (container: HTMLElement | null, hash: string): HTMLElement | null => {
return container && typeof(window) !== 'undefined' && hash
? container.querySelector(`[id="${hash.replace(/^#/, '')}"]`)
Expand All @@ -53,7 +59,7 @@ const scrollToTopOrHashManager = (
return;
}
if (previous?.page !== current.page) {
scrollToTargetOrTop(container, current.hash, Boolean(previous));
scrollToTargetOrTop(container, current.hash);
} else if (previous?.hash !== current.hash) {
scrollToTarget(container, current.hash);
}
Expand Down

0 comments on commit a39ed17

Please sign in to comment.