mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-31 04:41:32 +02:00
* Initial plan * Fix selected item outline overlapping next item in dropdown menus Replace position:relative + absolute positioning with flexbox layout on .dropdown-item to prevent stacking context overlap of active outline. Co-authored-by: aeaton-overleaf <75253002+aeaton-overleaf@users.noreply.github.com> * Fix invalid HTML - replace `div` with `span` inside dropdown item description container * Do not suppress keyboard focus outlines in toolbar dropdown menus * Add explicit keyboard focus ring for dropdown items * Avoid overlapping link focus rings with inset box-shadow --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: aeaton-overleaf <75253002+aeaton-overleaf@users.noreply.github.com> Co-authored-by: Rebeka <o.dekany@gmail.com> GitOrigin-RevId: ce4d1b01f04476fd154b6c05a52fc5632bf8b8dc
145 lines
3.6 KiB
TypeScript
145 lines
3.6 KiB
TypeScript
import React, { forwardRef } from 'react'
|
|
import {
|
|
Dropdown as BS5Dropdown,
|
|
DropdownToggle as BS5DropdownToggle,
|
|
DropdownMenu as BS5DropdownMenu,
|
|
DropdownItem as BS5DropdownItem,
|
|
DropdownDivider as BS5DropdownDivider,
|
|
DropdownHeader as BS5DropdownHeader,
|
|
Button as BS5Button,
|
|
} from 'react-bootstrap'
|
|
import type {
|
|
DropdownProps,
|
|
DropdownItemProps,
|
|
DropdownToggleProps,
|
|
DropdownMenuProps,
|
|
DropdownDividerProps,
|
|
DropdownHeaderProps,
|
|
} from '@/shared/components/types/dropdown-menu-props'
|
|
import MaterialIcon from '@/shared/components/material-icon'
|
|
import { fixedForwardRef } from '@/utils/react'
|
|
import classnames from 'classnames'
|
|
|
|
export function Dropdown({ ...props }: DropdownProps) {
|
|
return <BS5Dropdown {...props} />
|
|
}
|
|
|
|
function DropdownItem(
|
|
{
|
|
active,
|
|
children,
|
|
className,
|
|
description,
|
|
leadingIcon,
|
|
trailingIcon,
|
|
...props
|
|
}: DropdownItemProps,
|
|
ref: React.ForwardedRef<typeof BS5DropdownItem>
|
|
) {
|
|
let leadingIconComponent = null
|
|
if (leadingIcon) {
|
|
if (typeof leadingIcon === 'string') {
|
|
leadingIconComponent = (
|
|
<MaterialIcon
|
|
className="dropdown-item-leading-icon"
|
|
type={leadingIcon}
|
|
/>
|
|
)
|
|
} else {
|
|
leadingIconComponent = (
|
|
<span className="dropdown-item-leading-icon" aria-hidden="true">
|
|
{leadingIcon}
|
|
</span>
|
|
)
|
|
}
|
|
}
|
|
|
|
let trailingIconComponent = null
|
|
if (trailingIcon) {
|
|
if (typeof trailingIcon === 'string') {
|
|
const trailingIconType = active ? 'check' : trailingIcon
|
|
|
|
trailingIconComponent = (
|
|
<MaterialIcon
|
|
className="dropdown-item-trailing-icon"
|
|
type={trailingIconType}
|
|
/>
|
|
)
|
|
} else {
|
|
trailingIconComponent = (
|
|
<span className="dropdown-item-trailing-icon" aria-hidden="true">
|
|
{trailingIcon}
|
|
</span>
|
|
)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<BS5DropdownItem
|
|
active={active}
|
|
className={className}
|
|
role="menuitem"
|
|
{...props}
|
|
ref={ref}
|
|
>
|
|
{leadingIconComponent}
|
|
{description ? (
|
|
<span className="dropdown-item-description-container">
|
|
{children}
|
|
<span className="dropdown-item-description">{description}</span>
|
|
</span>
|
|
) : (
|
|
children
|
|
)}
|
|
{trailingIconComponent}
|
|
</BS5DropdownItem>
|
|
)
|
|
}
|
|
|
|
function EmptyLeadingIcon() {
|
|
return <span className="dropdown-item-leading-icon-empty" />
|
|
}
|
|
|
|
const ForwardReferredDropdownItem = fixedForwardRef(DropdownItem, {
|
|
EmptyLeadingIcon,
|
|
})
|
|
|
|
export { ForwardReferredDropdownItem as DropdownItem }
|
|
|
|
export const DropdownToggleCustom = forwardRef<
|
|
HTMLButtonElement,
|
|
React.ComponentProps<typeof BS5Button>
|
|
>(({ children, className, ...props }, ref) => (
|
|
<BS5Button
|
|
ref={ref}
|
|
className={classnames('custom-toggle', className)}
|
|
{...props}
|
|
>
|
|
{children}
|
|
<MaterialIcon type="expand_more" />
|
|
</BS5Button>
|
|
))
|
|
DropdownToggleCustom.displayName = 'DropdownToggleCustom'
|
|
|
|
export const DropdownToggle = forwardRef<
|
|
typeof BS5DropdownToggle,
|
|
DropdownToggleProps
|
|
>((props, ref) => <BS5DropdownToggle {...props} ref={ref} />)
|
|
DropdownToggle.displayName = 'DropdownToggle'
|
|
|
|
export const DropdownMenu = forwardRef<
|
|
typeof BS5DropdownMenu,
|
|
DropdownMenuProps
|
|
>(({ as = 'ul', ...props }, ref) => {
|
|
return <BS5DropdownMenu as={as} role="menu" {...props} ref={ref} />
|
|
})
|
|
DropdownMenu.displayName = 'DropdownMenu'
|
|
|
|
export function DropdownDivider({ as = 'li', ...props }: DropdownDividerProps) {
|
|
return <BS5DropdownDivider as={as} {...props} />
|
|
}
|
|
|
|
export function DropdownHeader({ as = 'li', ...props }: DropdownHeaderProps) {
|
|
return <BS5DropdownHeader as={as} {...props} />
|
|
}
|