Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/ui/button/Button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
8 changes: 6 additions & 2 deletions src/components/ui/button/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ const {
:as
:as-child
:disabled="disabled || loading"
:aria-busy="loading || undefined"
:class="cn(buttonVariants({ variant, size }), customClass)"
>
<i v-if="loading" class="pi pi-spin pi-spinner" />
<slot v-if="!loading" />
<i v-if="loading" class="pi pi-spin pi-spinner" aria-hidden="true" />
<template v-if="loading">
<span class="sr-only"><slot /></span>
</template>
<slot v-else />
</Primitive>
</template>
Loading