[cm6] fix toolbar overflow menu alignment (#13873)

GitOrigin-RevId: a70cf3fa37d49b9ed52fea4b928d52ffc2dbf136
This commit is contained in:
Domagoj Kriskovic 2023-07-18 12:37:04 +02:00 committed by Copybot
parent 05165682ba
commit 9c185d6f35
2 changed files with 25 additions and 38 deletions

View file

@ -43,7 +43,6 @@ const Toolbar = memo(function Toolbar() {
const [overflowed, setOverflowed] = useState(false)
const [collapsed, setCollapsed] = useState(false)
const overflowBeforeRef = useRef<HTMLDivElement>(null)
const overflowedItemsRef = useRef<Set<string>>(new Set())
const languageName = state.facet(language)?.name
@ -62,7 +61,6 @@ const Toolbar = memo(function Toolbar() {
setOverflowOpen(false)
setOverflowed(true)
if (overflowBeforeRef.current) {
overflowedItemsRef.current = new Set()
const buttonGroups = [
@ -85,7 +83,6 @@ const Toolbar = memo(function Toolbar() {
}
setOverflowed(overflowedItemsRef.current.size > 0)
}
},
[setOverflowOpen]
)
@ -117,13 +114,9 @@ const Toolbar = memo(function Toolbar() {
visual={visual}
listDepth={listDepth}
/>
<div
className="ol-cm-toolbar-button-group ol-cm-toolbar-stretch"
ref={overflowBeforeRef}
>
<div className="ol-cm-toolbar-button-group ol-cm-toolbar-stretch">
<ToolbarOverflow
overflowed={overflowed}
target={overflowBeforeRef.current ?? undefined}
overflowOpen={overflowOpen}
setOverflowOpen={setOverflowOpen}
overflowRef={overflowRef}

View file

@ -1,4 +1,4 @@
import { FC, LegacyRef } from 'react'
import { FC, LegacyRef, useRef } from 'react'
import { Button, Overlay, Popover } from 'react-bootstrap'
import classnames from 'classnames'
import Icon from '../../../../shared/components/icon'
@ -6,18 +6,11 @@ import { useCodeMirrorViewContext } from '../codemirror-editor'
export const ToolbarOverflow: FC<{
overflowed: boolean
target?: HTMLDivElement
overflowOpen: boolean
setOverflowOpen: (open: boolean) => void
overflowRef?: LegacyRef<Popover>
}> = ({
overflowed,
target,
overflowOpen,
setOverflowOpen,
overflowRef,
children,
}) => {
}> = ({ overflowed, overflowOpen, setOverflowOpen, overflowRef, children }) => {
const buttonRef = useRef<Button>(null)
const view = useCodeMirrorViewContext()
const className = classnames(
@ -31,6 +24,7 @@ export const ToolbarOverflow: FC<{
return (
<>
<Button
ref={buttonRef}
type="button"
id="toolbar-more"
className={className}
@ -49,7 +43,7 @@ export const ToolbarOverflow: FC<{
<Overlay
show={overflowOpen}
target={target}
target={buttonRef.current ?? undefined}
placement="bottom"
container={view.dom}
containerPadding={0}