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

[EuiResizableContainer] Initialize after DOM is ready #4447

Merged
merged 7 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
49 changes: 30 additions & 19 deletions src-docs/src/views/resizable_container/resizable_container_basic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { EuiText, EuiResizableContainer } from '../../../../src/components';
import { fake } from 'faker';

Expand All @@ -10,23 +10,34 @@ const text = (
</>
);

export default () => (
<EuiResizableContainer style={{ height: '200px' }}>
{(EuiResizablePanel, EuiResizableButton) => (
<>
<EuiResizablePanel initialSize={50} minSize="30%">
<EuiText>
<div>{text}</div>
<a href="">Hello world</a>
</EuiText>
</EuiResizablePanel>
export default () => {
const dom = useRef();
const [styles, setStyles] = useState({ display: 'none' });
useEffect(() => {
if (!dom.current) return;
dom.current.innerHTML = 'YOLO';
});
useEffect(() => {
setTimeout(() => setStyles({ display: 'flex' }), 1000);
}, []);
return (
<EuiResizableContainer style={{ ...styles, height: '200px' }}>
{(EuiResizablePanel, EuiResizableButton) => (
<>
<EuiResizablePanel initialSize={50} minSize="30%">
<EuiText>
<div>{text}</div>
<a href="">Hello world</a>
</EuiText>
</EuiResizablePanel>

<EuiResizableButton />
<EuiResizableButton />

<EuiResizablePanel initialSize={50} minSize="200px">
<EuiText>{text}</EuiText>
</EuiResizablePanel>
</>
)}
</EuiResizableContainer>
);
<EuiResizablePanel initialSize={50} minSize="200px">
<div ref={dom} />
</EuiResizablePanel>
</>
)}
</EuiResizableContainer>
);
};
6 changes: 4 additions & 2 deletions src/components/resizable_container/resizable_container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ export const EuiResizableContainer: FunctionComponent<EuiResizableContainerProps
);

useEffect(() => {
initialize();
if (containerSize.width > 0 && containerSize.height > 0) {
initialize();
}
}, [initialize, containerSize]);

const onMouseDown = useCallback(
Expand Down Expand Up @@ -273,7 +275,7 @@ export const EuiResizableContainer: FunctionComponent<EuiResizableContainerProps
onTouchMove={onMouseMove}
onTouchEnd={onMouseUp}
{...rest}>
{!!reducerState.containerSize && render()}
{render()}
</div>
</EuiResizableContainerContextProvider>
);
Expand Down