diff --git a/app/components/form/fields/DateTimeRangePicker.spec.tsx b/app/components/form/fields/DateTimeRangePicker.spec.tsx index dd418db2de..149f13ae11 100644 --- a/app/components/form/fields/DateTimeRangePicker.spec.tsx +++ b/app/components/form/fields/DateTimeRangePicker.spec.tsx @@ -76,8 +76,8 @@ describe('custom mode', () => { expect(onChange).not.toBeCalled() expect(screen.getByLabelText('Start time')).toBeEnabled() - expect(screen.getByRole('button', { name: 'Reset' })).toBeDisabled() - expect(screen.getByRole('button', { name: 'Load' })).toBeDisabled() + expect(screen.getByRole('button', { name: 'Reset' })).toHaveClass('visually-disabled') + expect(screen.getByRole('button', { name: 'Load' })).toHaveClass('visually-disabled') }) it('clicking load after changing date changes range', async () => { diff --git a/libs/ui/lib/button/Button.tsx b/libs/ui/lib/button/Button.tsx index 9c845d775d..66e882ee22 100644 --- a/libs/ui/lib/button/Button.tsx +++ b/libs/ui/lib/button/Button.tsx @@ -1,4 +1,5 @@ import cn from 'classnames' +import type { MouseEventHandler } from 'react' import { forwardRef } from 'react' import { Spinner } from '@oxide/ui' @@ -90,18 +91,45 @@ export const buttonStyle = ({ ) } +/** + * When the `disabled` prop is passed to the button we put it in a visually disabled state. + * In that case we want to override the default mouse down and click behavior to simulate a + * disabled state. + */ +const noop: MouseEventHandler = (e) => { + e.stopPropagation() + e.preventDefault() +} + // Use `forwardRef` so the ref points to the DOM element (not the React Component) // so it can be focused using the DOM API (eg. this.buttonRef.current.focus()) export const Button = forwardRef( ( - { children, size, variant, color, className, loading, innerClassName, ...rest }, + { + children, + size, + variant, + color, + className, + loading, + innerClassName, + disabled, + onClick, + 'aria-disabled': ariaDisabled, + ...rest + }, ref ) => { return (