Skip to content

Commit

Permalink
Merge pull request #3819 from ProjectMirador/mui5-scrollto
Browse files Browse the repository at this point in the history
Use an explicit dom ref for handling scrolling to dom elements
  • Loading branch information
jcoyne authored Nov 27, 2023
2 parents f5a087f + 40db475 commit bf8ba15
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
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

0 comments on commit bf8ba15

Please sign in to comment.