Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an explicit dom ref for handling scrolling to dom elements #3819

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/src/components/ScrollTo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('ScrollTo', () => {
containerRef = createRef();
render(<div data-testid="container" ref={containerRef} />);

containerRef.current.domEl = {
containerRef.current = {
getBoundingClientRect: () => containerBoundingRect,
getElementsByClassName: () => [{ scrollTo }],
};
Expand Down
8 changes: 7 additions & 1 deletion src/components/CompanionWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class CompanionWindow extends Component {
const {
ariaLabel, classes, paperClassName, onCloseClick, updateCompanionWindow, isDisplayed,
position, t, title, children, titleControls, size,
defaultSidebarPanelWidth, defaultSidebarPanelHeight,
defaultSidebarPanelWidth, defaultSidebarPanelHeight, innerRef,
} = this.props;

const isBottom = (position === 'bottom' || position === 'far-bottom');
Expand All @@ -112,6 +112,7 @@ export class CompanionWindow extends Component {

return (
<Paper
ref={innerRef}
sx={{
boxShadow: 'none',
boxSizing: 'border-box',
Expand Down Expand Up @@ -251,6 +252,10 @@ CompanionWindow.propTypes = {
defaultSidebarPanelHeight: PropTypes.number,
defaultSidebarPanelWidth: PropTypes.number,
direction: PropTypes.string.isRequired,
innerRef: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
]),
isDisplayed: PropTypes.bool,
onCloseClick: PropTypes.func,
paperClassName: PropTypes.string,
Expand All @@ -271,6 +276,7 @@ CompanionWindow.defaultProps = {
classes: {},
defaultSidebarPanelHeight: 201,
defaultSidebarPanelWidth: 235,
innerRef: undefined,
isDisplayed: false,
onCloseClick: () => {},
paperClassName: '',
Expand Down
10 changes: 5 additions & 5 deletions src/components/ScrollTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export class ScrollTo extends Component {
containerBoundingRect() {
const { containerRef } = this.props;

if (!containerRef || !containerRef.current || !containerRef.current.domEl) return {};
if (!containerRef || !containerRef.current) return {};

return containerRef.current.domEl.getBoundingClientRect();
return containerRef.current.getBoundingClientRect();
}

/**
Expand All @@ -59,14 +59,14 @@ export class ScrollTo extends Component {
}

/**
* The container provided in the containersRef dome structure in which scrolling
* The container provided in the containersRef dom structure in which scrolling
* should happen.
*/
scrollableContainer() {
const { containerRef } = this.props;

if (!containerRef || !containerRef.current || !containerRef.current.domEl) return null;
return containerRef.current.domEl.getElementsByClassName('mirador-scrollto-scrollable')[0];
if (!containerRef || !containerRef.current) return null;
return containerRef.current.getElementsByClassName('mirador-scrollto-scrollable')[0];
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/components/SidebarIndexList.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class SidebarIndexList extends Component {
key={canvas.id}
sx={{
paddingRight: 1,
position: 'initial',
}}
divider
onClick={onClick}
Expand Down
1 change: 0 additions & 1 deletion src/components/WindowSideBarAnnotationsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class WindowSideBarAnnotationsPanel extends Component {
windowId={windowId}
id={id}
ref={this.containerRef}
otherRef={this.containerRef}
titleControls={<AnnotationSettings windowId={windowId} />}
>
<StyledSection sx={{
Expand Down
1 change: 0 additions & 1 deletion src/components/WindowSideBarCanvasPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export class WindowSideBarCanvasPanel extends Component {
id={id}
windowId={windowId}
ref={this.containerRef}
otherRef={this.containerRef}
titleControls={(
<>
{
Expand Down