♿️(frontend) focus first background effect button on panel open
improves keyboard navigation by placing focus on first actionable element
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
|
import { forwardRef, ReactNode } from 'react'
|
||||||
import {
|
import {
|
||||||
ToggleButton as RACToggleButton,
|
ToggleButton as RACToggleButton,
|
||||||
ToggleButtonProps as RACToggleButtonProps,
|
ToggleButtonProps as RACToggleButtonProps,
|
||||||
} from 'react-aria-components'
|
} from 'react-aria-components'
|
||||||
import { type ButtonRecipeProps, buttonRecipe } from './buttonRecipe'
|
import { type ButtonRecipeProps, buttonRecipe } from './buttonRecipe'
|
||||||
import { TooltipWrapper, TooltipWrapperProps } from './TooltipWrapper'
|
import { TooltipWrapper, TooltipWrapperProps } from './TooltipWrapper'
|
||||||
import { ReactNode } from 'react'
|
|
||||||
|
|
||||||
export type ToggleButtonProps = RACToggleButtonProps &
|
export type ToggleButtonProps = RACToggleButtonProps &
|
||||||
ButtonRecipeProps &
|
ButtonRecipeProps &
|
||||||
@@ -16,24 +16,25 @@ export type ToggleButtonProps = RACToggleButtonProps &
|
|||||||
/**
|
/**
|
||||||
* React aria ToggleButton with our button styles, that can take a tooltip if needed
|
* React aria ToggleButton with our button styles, that can take a tooltip if needed
|
||||||
*/
|
*/
|
||||||
export const ToggleButton = ({
|
export const ToggleButton = forwardRef<HTMLButtonElement, ToggleButtonProps>(
|
||||||
tooltip,
|
({ tooltip, tooltipType, ...props }, ref) => {
|
||||||
tooltipType,
|
const [variantProps, componentProps] = buttonRecipe.splitVariantProps(props)
|
||||||
...props
|
|
||||||
}: ToggleButtonProps) => {
|
|
||||||
const [variantProps, componentProps] = buttonRecipe.splitVariantProps(props)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TooltipWrapper tooltip={tooltip} tooltipType={tooltipType}>
|
<TooltipWrapper tooltip={tooltip} tooltipType={tooltipType}>
|
||||||
<RACToggleButton
|
<RACToggleButton
|
||||||
{...componentProps}
|
ref={ref}
|
||||||
className={[buttonRecipe(variantProps), props.className].join(' ')}
|
{...componentProps}
|
||||||
>
|
className={[buttonRecipe(variantProps), props.className].join(' ')}
|
||||||
<>
|
>
|
||||||
{componentProps.children as ReactNode}
|
<>
|
||||||
{props.description && <span>{tooltip}</span>}
|
{componentProps.children as ReactNode}
|
||||||
</>
|
{props.description && <span>{tooltip}</span>}
|
||||||
</RACToggleButton>
|
</>
|
||||||
</TooltipWrapper>
|
</RACToggleButton>
|
||||||
)
|
</TooltipWrapper>
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
ToggleButton.displayName = 'ToggleButton'
|
||||||
|
|||||||
Reference in New Issue
Block a user