mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
[cm6] fix toolbar overflow menu alignment (#13873)
GitOrigin-RevId: a70cf3fa37d49b9ed52fea4b928d52ffc2dbf136
This commit is contained in:
parent
05165682ba
commit
9c185d6f35
2 changed files with 25 additions and 38 deletions
|
@ -43,7 +43,6 @@ const Toolbar = memo(function Toolbar() {
|
||||||
const [overflowed, setOverflowed] = useState(false)
|
const [overflowed, setOverflowed] = useState(false)
|
||||||
const [collapsed, setCollapsed] = useState(false)
|
const [collapsed, setCollapsed] = useState(false)
|
||||||
|
|
||||||
const overflowBeforeRef = useRef<HTMLDivElement>(null)
|
|
||||||
const overflowedItemsRef = useRef<Set<string>>(new Set())
|
const overflowedItemsRef = useRef<Set<string>>(new Set())
|
||||||
|
|
||||||
const languageName = state.facet(language)?.name
|
const languageName = state.facet(language)?.name
|
||||||
|
@ -62,30 +61,28 @@ const Toolbar = memo(function Toolbar() {
|
||||||
setOverflowOpen(false)
|
setOverflowOpen(false)
|
||||||
setOverflowed(true)
|
setOverflowed(true)
|
||||||
|
|
||||||
if (overflowBeforeRef.current) {
|
overflowedItemsRef.current = new Set()
|
||||||
overflowedItemsRef.current = new Set()
|
|
||||||
|
|
||||||
const buttonGroups = [
|
const buttonGroups = [
|
||||||
...element.querySelectorAll<HTMLDivElement>('[data-overflow]'),
|
...element.querySelectorAll<HTMLDivElement>('[data-overflow]'),
|
||||||
].reverse()
|
].reverse()
|
||||||
|
|
||||||
// restore all the overflowed items
|
// restore all the overflowed items
|
||||||
for (const buttonGroup of buttonGroups) {
|
for (const buttonGroup of buttonGroups) {
|
||||||
buttonGroup.classList.remove('overflow-hidden')
|
buttonGroup.classList.remove('overflow-hidden')
|
||||||
}
|
|
||||||
|
|
||||||
// find all the available items
|
|
||||||
for (const buttonGroup of buttonGroups) {
|
|
||||||
if (element.scrollWidth <= element.clientWidth) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
// add this item to the overflow
|
|
||||||
overflowedItemsRef.current.add(buttonGroup.dataset.overflow!)
|
|
||||||
buttonGroup.classList.add('overflow-hidden')
|
|
||||||
}
|
|
||||||
|
|
||||||
setOverflowed(overflowedItemsRef.current.size > 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// find all the available items
|
||||||
|
for (const buttonGroup of buttonGroups) {
|
||||||
|
if (element.scrollWidth <= element.clientWidth) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// add this item to the overflow
|
||||||
|
overflowedItemsRef.current.add(buttonGroup.dataset.overflow!)
|
||||||
|
buttonGroup.classList.add('overflow-hidden')
|
||||||
|
}
|
||||||
|
|
||||||
|
setOverflowed(overflowedItemsRef.current.size > 0)
|
||||||
},
|
},
|
||||||
[setOverflowOpen]
|
[setOverflowOpen]
|
||||||
)
|
)
|
||||||
|
@ -117,13 +114,9 @@ const Toolbar = memo(function Toolbar() {
|
||||||
visual={visual}
|
visual={visual}
|
||||||
listDepth={listDepth}
|
listDepth={listDepth}
|
||||||
/>
|
/>
|
||||||
<div
|
<div className="ol-cm-toolbar-button-group ol-cm-toolbar-stretch">
|
||||||
className="ol-cm-toolbar-button-group ol-cm-toolbar-stretch"
|
|
||||||
ref={overflowBeforeRef}
|
|
||||||
>
|
|
||||||
<ToolbarOverflow
|
<ToolbarOverflow
|
||||||
overflowed={overflowed}
|
overflowed={overflowed}
|
||||||
target={overflowBeforeRef.current ?? undefined}
|
|
||||||
overflowOpen={overflowOpen}
|
overflowOpen={overflowOpen}
|
||||||
setOverflowOpen={setOverflowOpen}
|
setOverflowOpen={setOverflowOpen}
|
||||||
overflowRef={overflowRef}
|
overflowRef={overflowRef}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { FC, LegacyRef } from 'react'
|
import { FC, LegacyRef, useRef } from 'react'
|
||||||
import { Button, Overlay, Popover } from 'react-bootstrap'
|
import { Button, Overlay, Popover } from 'react-bootstrap'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import Icon from '../../../../shared/components/icon'
|
import Icon from '../../../../shared/components/icon'
|
||||||
|
@ -6,18 +6,11 @@ import { useCodeMirrorViewContext } from '../codemirror-editor'
|
||||||
|
|
||||||
export const ToolbarOverflow: FC<{
|
export const ToolbarOverflow: FC<{
|
||||||
overflowed: boolean
|
overflowed: boolean
|
||||||
target?: HTMLDivElement
|
|
||||||
overflowOpen: boolean
|
overflowOpen: boolean
|
||||||
setOverflowOpen: (open: boolean) => void
|
setOverflowOpen: (open: boolean) => void
|
||||||
overflowRef?: LegacyRef<Popover>
|
overflowRef?: LegacyRef<Popover>
|
||||||
}> = ({
|
}> = ({ overflowed, overflowOpen, setOverflowOpen, overflowRef, children }) => {
|
||||||
overflowed,
|
const buttonRef = useRef<Button>(null)
|
||||||
target,
|
|
||||||
overflowOpen,
|
|
||||||
setOverflowOpen,
|
|
||||||
overflowRef,
|
|
||||||
children,
|
|
||||||
}) => {
|
|
||||||
const view = useCodeMirrorViewContext()
|
const view = useCodeMirrorViewContext()
|
||||||
|
|
||||||
const className = classnames(
|
const className = classnames(
|
||||||
|
@ -31,6 +24,7 @@ export const ToolbarOverflow: FC<{
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
|
ref={buttonRef}
|
||||||
type="button"
|
type="button"
|
||||||
id="toolbar-more"
|
id="toolbar-more"
|
||||||
className={className}
|
className={className}
|
||||||
|
@ -49,7 +43,7 @@ export const ToolbarOverflow: FC<{
|
||||||
|
|
||||||
<Overlay
|
<Overlay
|
||||||
show={overflowOpen}
|
show={overflowOpen}
|
||||||
target={target}
|
target={buttonRef.current ?? undefined}
|
||||||
placement="bottom"
|
placement="bottom"
|
||||||
container={view.dom}
|
container={view.dom}
|
||||||
containerPadding={0}
|
containerPadding={0}
|
||||||
|
|
Loading…
Reference in a new issue