mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-09 18:39:11 +00:00
Merge pull request #17568 from overleaf/rd-b5-button-fix
[web] Fix the Button component accessibility label GitOrigin-RevId: 1d157fca370c5e0425890468d7cad169d0261c23
This commit is contained in:
parent
44d0b947ce
commit
b1c40d05f7
8 changed files with 22 additions and 17 deletions
|
@ -1,22 +1,17 @@
|
|||
import { useTranslation } from 'react-i18next'
|
||||
import MaterialIcon from '@/shared/components/material-icon'
|
||||
import Button from './button'
|
||||
import type { IconButtonProps } from '@/features/ui/components/types/icon-button-props'
|
||||
import classNames from 'classnames'
|
||||
|
||||
export default function IconButton({
|
||||
accessibilityLabel,
|
||||
icon,
|
||||
isLoading = false,
|
||||
size = 'default',
|
||||
...props
|
||||
}: IconButtonProps) {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const iconButtonClassName = `icon-button-${size}`
|
||||
const iconSizeClassName =
|
||||
size === 'large'
|
||||
? 'leading-trailing-icon-large'
|
||||
: 'leading-trailing-icon-small'
|
||||
const iconSizeClassName = size === 'large' ? 'icon-large' : 'icon-small'
|
||||
const materialIconClassName = classNames(iconSizeClassName, {
|
||||
'button-content-hidden': isLoading,
|
||||
})
|
||||
|
@ -24,7 +19,7 @@ export default function IconButton({
|
|||
return (
|
||||
<Button className={iconButtonClassName} isLoading={isLoading} {...props}>
|
||||
<MaterialIcon
|
||||
accessibilityLabel={t('add')}
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
className={materialIconClassName}
|
||||
type={icon}
|
||||
/>
|
||||
|
|
|
@ -10,10 +10,7 @@ export default function IconTextButton({
|
|||
trailingIcon,
|
||||
...props
|
||||
}: IconTextButtonProps) {
|
||||
const materialIconClassName =
|
||||
size === 'large'
|
||||
? 'leading-trailing-icon-large'
|
||||
: 'leading-trailing-icon-small'
|
||||
const materialIconClassName = size === 'large' ? 'icon-large' : 'icon-small'
|
||||
|
||||
return (
|
||||
<Button size={size} {...props}>
|
||||
|
|
|
@ -10,6 +10,7 @@ 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,
|
||||
|
@ -31,7 +32,11 @@ export function SplitButton({
|
|||
variant={variant}
|
||||
{...props}
|
||||
>
|
||||
<MaterialIcon className="split-button-caret" type="expand_more" />
|
||||
<MaterialIcon
|
||||
className="split-button-caret"
|
||||
type="expand_more"
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
/>
|
||||
</DropdownToggle>
|
||||
<DropdownMenu>
|
||||
{items.map((item, index) => (
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { ButtonProps } from './button-props'
|
||||
|
||||
export type IconButtonProps = ButtonProps & {
|
||||
accessibilityLabel?: string
|
||||
icon: string
|
||||
type?: 'button'
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ export type SplitButtonVariants = Extract<
|
|||
>
|
||||
|
||||
export type SplitButtonProps = PropsWithChildren<{
|
||||
accessibilityLabel?: string
|
||||
align?: DropdownProps['align']
|
||||
disabled?: boolean
|
||||
id: DropdownToggleProps['id']
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import IconButton from '@/features/ui/components/bootstrap-5/icon-button'
|
||||
import type { Meta } from '@storybook/react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
type Args = React.ComponentProps<typeof IconButton>
|
||||
|
||||
export const Icon = (args: Args) => {
|
||||
return <IconButton disabled {...args} />
|
||||
const { t } = useTranslation()
|
||||
|
||||
return <IconButton accessibilityLabel={t('add')} disabled {...args} />
|
||||
}
|
||||
|
||||
const meta: Meta<typeof IconButton> = {
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import { SplitButton } from '@/features/ui/components/bootstrap-5/split-button'
|
||||
import type { Meta } from '@storybook/react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
type Args = React.ComponentProps<typeof SplitButton>
|
||||
|
||||
export const Dropdown = (args: Args) => {
|
||||
return <SplitButton {...args} />
|
||||
const { t } = useTranslation()
|
||||
|
||||
return <SplitButton accessibilityLabel={t('expand')} {...args} />
|
||||
}
|
||||
const meta: Meta<typeof SplitButton> = {
|
||||
title: 'Shared/Components/Bootstrap 5/SplitButton',
|
||||
|
|
|
@ -35,11 +35,11 @@
|
|||
align-items: center;
|
||||
gap: var(--spacing-04); // Add gap between text and icons
|
||||
|
||||
.leading-trailing-icon-small {
|
||||
.icon-small {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.leading-trailing-icon-large {
|
||||
.icon-large {
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue