overleaf/services/web/frontend/js/features/ui/components/bootstrap-5/split-button.tsx
Rebeka Dekany b1c40d05f7 Merge pull request #17568 from overleaf/rd-b5-button-fix
[web] Fix the Button component accessibility label

GitOrigin-RevId: 1d157fca370c5e0425890468d7cad169d0261c23
2024-03-28 09:04:02 +00:00

51 lines
1.3 KiB
TypeScript

import classNames from 'classnames'
import Button from './button'
import {
Dropdown,
DropdownItem,
DropdownMenu,
DropdownToggle,
} from './dropdown-menu'
import MaterialIcon from '@/shared/components/material-icon'
import type { SplitButtonProps } from '@/features/ui/components/types/split-button-props'
export function SplitButton({
accessibilityLabel,
align,
id,
items,
text,
variant,
...props
}: SplitButtonProps) {
const buttonClassName = classNames('split-button')
return (
<div>
<Dropdown align={align}>
<Button className={buttonClassName} variant={variant} {...props}>
<span className="split-button-content">{text}</span>
</Button>
<DropdownToggle
bsPrefix="dropdown-button-toggle"
id={id}
variant={variant}
{...props}
>
<MaterialIcon
className="split-button-caret"
type="expand_more"
accessibilityLabel={accessibilityLabel}
/>
</DropdownToggle>
<DropdownMenu>
{items.map((item, index) => (
<DropdownItem key={index} eventKey={item.eventKey}>
{item.label}
</DropdownItem>
))}
</DropdownMenu>
</Dropdown>
</div>
)
}