diff --git a/src/components/ui/button/Button.test.ts b/src/components/ui/button/Button.test.ts index cb986f98f34..bdc8affd466 100644 --- a/src/components/ui/button/Button.test.ts +++ b/src/components/ui/button/Button.test.ts @@ -27,16 +27,19 @@ describe('Button', () => { expect(onClick).toHaveBeenCalledTimes(1) }) - it('hides slot content, shows a spinner, and disables the button while loading', () => { + // The label stays in the accessibility tree while loading, so the control is + // still announced by name rather than as an unlabelled button. + it('swaps slot content for a spinner and disables the button while loading', () => { const { container } = render(Button, { props: { loading: true }, slots: { default: 'Submit' } }) - expect(screen.queryByText('Submit')).not.toBeInTheDocument() + const button = screen.getByRole('button', { name: 'Submit' }) + expect(button).toBeDisabled() + expect(button).toHaveAttribute('aria-busy', 'true') // eslint-disable-next-line testing-library/no-container, testing-library/no-node-access -- PrimeVue spinner icon has no accessible role expect(container.querySelector('.pi-spin')).toBeInTheDocument() - expect(screen.getByRole('button')).toBeDisabled() }) it('does not fire click when loading', async () => { diff --git a/src/components/ui/button/Button.vue b/src/components/ui/button/Button.vue index bd607238739..d32be57cdad 100644 --- a/src/components/ui/button/Button.vue +++ b/src/components/ui/button/Button.vue @@ -29,9 +29,13 @@ const { :as :as-child :disabled="disabled || loading" + :aria-busy="loading || undefined" :class="cn(buttonVariants({ variant, size }), customClass)" > - - +