mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #13038 from overleaf/ii-history-react-dropdowns
[web] Adjust dropdowns placement in history list GitOrigin-RevId: 050e16b97630eb37c890ad9a97a56ba882cca06b
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import { forwardRef } from 'react'
|
||||
import classnames from 'classnames'
|
||||
// @ts-ignore
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import RootCloseWrapper from 'react-overlays/lib/RootCloseWrapper'
|
||||
import { DropdownProps } from 'react-bootstrap'
|
||||
import { MergeAndOverride } from '../../../../../types/utils'
|
||||
|
||||
type DropdownMenuWithRefProps = MergeAndOverride<
|
||||
Pick<DropdownProps, 'bsClass' | 'open' | 'pullRight' | 'onClose'>,
|
||||
{
|
||||
children: React.ReactNode
|
||||
bsRole: 'menu'
|
||||
menuRef: React.MutableRefObject<HTMLElement | undefined>
|
||||
className?: string
|
||||
// The props below are passed by react-bootstrap
|
||||
labelledBy?: string | undefined
|
||||
rootCloseEvent?: 'click' | 'mousedown' | undefined
|
||||
}
|
||||
>
|
||||
|
||||
const DropdownMenuWithRef = forwardRef<
|
||||
HTMLUListElement,
|
||||
DropdownMenuWithRefProps
|
||||
>(function (props, ref) {
|
||||
const {
|
||||
children,
|
||||
bsRole,
|
||||
bsClass,
|
||||
className,
|
||||
open,
|
||||
pullRight,
|
||||
labelledBy,
|
||||
menuRef,
|
||||
onClose,
|
||||
rootCloseEvent,
|
||||
...rest
|
||||
} = props
|
||||
|
||||
// expose the menu reference to both the `menuRef` and `ref callback` from react-bootstrap
|
||||
const handleRefs = (node: HTMLUListElement) => {
|
||||
if (typeof ref === 'function') {
|
||||
ref(node)
|
||||
}
|
||||
menuRef.current = node
|
||||
}
|
||||
|
||||
// Implementation as suggested in
|
||||
// https://react-bootstrap-v3.netlify.app/components/dropdowns/#btn-dropdowns-props-dropdown
|
||||
return (
|
||||
<RootCloseWrapper
|
||||
disabled={!open}
|
||||
onRootClose={onClose}
|
||||
event={rootCloseEvent}
|
||||
>
|
||||
<ul
|
||||
role={bsRole}
|
||||
className={classnames(className, bsClass, {
|
||||
'dropdown-menu-right': pullRight,
|
||||
})}
|
||||
aria-labelledby={labelledBy}
|
||||
ref={handleRefs}
|
||||
{...rest}
|
||||
>
|
||||
{children}
|
||||
</ul>
|
||||
</RootCloseWrapper>
|
||||
)
|
||||
})
|
||||
DropdownMenuWithRef.displayName = 'DropdownMenuWithRef'
|
||||
|
||||
export default DropdownMenuWithRef
|
||||
+4
-1
@@ -5,7 +5,7 @@ import { DropdownProps } from 'react-bootstrap'
|
||||
import { MergeAndOverride } from '../../../../../types/utils'
|
||||
|
||||
type CustomToggleProps = MergeAndOverride<
|
||||
Pick<DropdownProps, 'bsClass'>,
|
||||
Pick<DropdownProps, 'bsClass' | 'open'>,
|
||||
{
|
||||
children: React.ReactNode
|
||||
bsRole: 'toggle'
|
||||
@@ -23,6 +23,7 @@ const DropdownToggleWithTooltip = forwardRef<
|
||||
children,
|
||||
bsClass,
|
||||
className,
|
||||
open,
|
||||
bsRole: _bsRole,
|
||||
...rest
|
||||
} = props
|
||||
@@ -33,6 +34,8 @@ const DropdownToggleWithTooltip = forwardRef<
|
||||
type="button"
|
||||
ref={ref}
|
||||
className={classnames(bsClass, 'btn', className)}
|
||||
aria-expanded={open}
|
||||
aria-haspopup="true"
|
||||
{...rest}
|
||||
>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user