fix: make search options open on top of tags container

This commit is contained in:
Antonella Sgarlatta
2021-06-23 12:44:16 -03:00
parent 39a3d56d8f
commit 28aab95bc0

View File

@@ -27,7 +27,10 @@ const SearchOptions = observer(({ appState }: Props) => {
} = searchOptions; } = searchOptions;
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [optionsPanelTop, setOptionsPanelTop] = useState(0); const [position, setPosition] = useState({
top: 0,
right: 0,
});
const buttonRef = useRef<HTMLButtonElement>(); const buttonRef = useRef<HTMLButtonElement>();
const panelRef = useRef<HTMLDivElement>(); const panelRef = useRef<HTMLDivElement>();
const [closeOnBlur, setLockCloseOnBlur] = useCloseOnBlur(panelRef, setOpen); const [closeOnBlur, setLockCloseOnBlur] = useCloseOnBlur(panelRef, setOpen);
@@ -45,9 +48,12 @@ const SearchOptions = observer(({ appState }: Props) => {
<Disclosure <Disclosure
open={open} open={open}
onChange={() => { onChange={() => {
const { height } = buttonRef.current.getBoundingClientRect(); const rect = buttonRef.current.getBoundingClientRect();
setOptionsPanelTop(height); setPosition({
setOpen((prevOpen) => !prevOpen); top: rect.bottom,
right: document.body.clientWidth - rect.right,
});
setOpen(!open);
}} }}
> >
<DisclosureButton <DisclosureButton
@@ -61,9 +67,9 @@ const SearchOptions = observer(({ appState }: Props) => {
<DisclosurePanel <DisclosurePanel
ref={panelRef} ref={panelRef}
style={{ style={{
top: optionsPanelTop, ...position,
}} }}
className="sn-dropdown sn-dropdown--anchor-right sn-dropdown--animated min-w-80 absolute grid gap-2 py-2" className="sn-dropdown sn-dropdown--animated min-w-80 fixed grid gap-2 py-2"
onBlur={closeOnBlur} onBlur={closeOnBlur}
> >
<Switch <Switch