-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Dropdown menus do not pop over sidebars but instead result in scrollbars in the sidebar #4156
Comments
Have you had any progress on this topic? I see using Portal as a potential solution to this problem. Overlay could capture scroll events and close the Dropdown. https://codesandbox.io/s/react-semantic-ui-dropdown-issue-irg52 |
@radulle no |
the solution: |
here solution, enjoy: <DropdownPortal >
<Dropdown
.... function DropdownPortal( props:{children:React.ReactElement<DropdownProps>}) {
const { children } = props;
const [ state, setState ] = useState({ open:false });
const [ node, setNode ] = useState<HTMLElement | null>( null );
const [ root, setRoot ] = useState<HTMLElement | null>( null );
const dropdownref = useRef<React.Component<DropdownProps, HTMLElement>>( null );
const clone = useMemo( () => {
const { onOpen, onClose } = children.props;
return cloneElement( children, {
ref: dropdownref,
onOpen: ( ...args )=>{
setState({ open:true });
onOpen?.call( children, ...args );
},
onClose: ( ...args )=>{
setState({ open:false });
onClose?.call( children, ...args );
},
});
}, [ children ]);
useEffect( () => {
const target = dropdownref.current?.ref.current;
if ( target && target.lastChild && target.lastChild instanceof HTMLElement ) {
setNode( target.lastChild );
setRoot( target );
}
}, [ ]);
useEffect( () => {
if ( node && root ) {
if ( state.open ) {
const bounds = node.getBoundingClientRect();
document.body.appendChild( node );
node.style.position = 'absolute';
node.style.background = 'red';
node.style.top = bounds.top + 'px';
node.style.left = bounds.left + 'px';
} else {
root.append( node );
node.style.position = '';
node.style.background = '';
node.style.top = '';
node.style.left = '';
}
}
}, [state]);
return (
<>
{clone}
</>
);
} not work with |
Any chance this becomes a regular behavior? |
I'm currently doing a menuPortalTarget props on the dropdown, just posted yesterday, it might be close to finished. |
Bug Report
Dropdown menus do not pop over sidebars but instead result in scrollbars in the sidebar.
Steps
Expected Result
The menu options should be displayed over the Sidebar.
Actual Result
The menu options fill the Sidebar which now shows horizontal and/or vertical scrollbars.
Version
2.0.3
Testcase
https://codesandbox.io/s/prod-cookies-ilvo5
The text was updated successfully, but these errors were encountered: