Skip to content

Commit af09363

Browse files
authored
Merge pull request #3821 from fstoe/fix_sizing_addBar
Bug: sizing of workspaceAdd
2 parents 88cc3f9 + 0089f95 commit af09363

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/components/WorkspaceAdd.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRef, useState } from 'react';
1+
import { useRef, useState, useEffect } from 'react';
22
import PropTypes from 'prop-types';
33
import { styled } from '@mui/material/styles';
44
import classNames from 'classnames';
@@ -44,6 +44,14 @@ export function WorkspaceAdd({
4444
const { t } = useTranslation();
4545
const [addResourcesOpen, setAddResourcesVisibility] = useState(false);
4646
const ref = useRef();
47+
const [refWidth, setRefWidth] = useState('100%');
48+
49+
/** */
50+
const updateRefWidth = () => {
51+
if (ref.current) {
52+
setRefWidth(ref.current.offsetWidth);
53+
}
54+
};
4755

4856
/** */
4957
const handleDrop = ({ manifestId, manifestJson }, props, monitor) => {
@@ -84,9 +92,19 @@ export function WorkspaceAdd({
8492
addResource, catalog, setWorkspaceAddVisibility, t, ...rest,
8593
};
8694

95+
useEffect(() => {
96+
window.addEventListener('resize', updateRefWidth);
97+
98+
updateRefWidth();
99+
100+
return () => {
101+
window.removeEventListener('resize', updateRefWidth);
102+
};
103+
}, []);
104+
87105
return (
88106
<IIIFDropTarget onDrop={handleDrop}>
89-
<StyledWorkspaceAdd ref={ref} className={classNames(ns('workspace-add'))}>
107+
<StyledWorkspaceAdd className={classNames(ns('workspace-add'))} ref={ref}>
90108
{catalog.length < 1 ? (
91109
<Grid
92110
alignItems="center"
@@ -138,10 +156,8 @@ export function WorkspaceAdd({
138156
sx={theme => ({
139157
'.MuiDrawer-paper': {
140158
borderTop: '0',
141-
left: '0',
142-
[theme.breakpoints.up('sm')]: {
143-
left: '65px',
144-
},
159+
left: 'unset',
160+
width: refWidth,
145161
},
146162
...(!addResourcesOpen && {
147163
display: 'none',

0 commit comments

Comments
 (0)