Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gcds-button): Prevent gcdsClick event if button is disabled #724

Merged
merged 5 commits into from
Jan 10, 2025
Merged
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
4 changes: 2 additions & 2 deletions packages/web/src/components/gcds-button/gcds-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class GcdsButton {
/**
* The value attribute specifies the value for a <button> element.
*/
@Prop() value: string;
@Prop() value: string;

/**
* Link props
Expand Down Expand Up @@ -242,7 +242,7 @@ export class GcdsButton {
id={buttonId}
onBlur={() => this.gcdsBlur.emit()}
onFocus={() => this.gcdsFocus.emit()}
onClick={e => this.handleClick(e)}
onClick={e => !disabled && this.handleClick(e)}
class={`gcds-button button--role-${buttonRole} button--${size}`}
ref={element => (this.shadowElement = element as HTMLElement)}
{...inheritedAttributes}
Expand Down
24 changes: 24 additions & 0 deletions packages/web/src/components/gcds-button/test/gcds-button.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ describe('gcds-button', () => {
const element = await page.find('gcds-button');
expect(element.textContent).toEqual('Button Label');
});
it('fires gcdsClick event', async () => {
const page = await newE2EPage();

await page.setContent('<gcds-button>Button Label</gcds-button>');
const gcdsClick = await page.spyOnEvent('gcdsClick');
await page.keyboard.press('Tab');
await page.keyboard.press('Enter');

await page.waitForChanges();

expect(gcdsClick.events.length).toBe(1);
});
it('disabled - will not fire gcdsClick event', async () => {
const page = await newE2EPage();

await page.setContent('<gcds-button disabled>Button Label</gcds-button>');
const gcdsClick = await page.spyOnEvent('gcdsClick');
await page.keyboard.press('Tab');
await page.keyboard.press('Enter');

await page.waitForChanges();

expect(gcdsClick.events.length).toBe(0);
});
});

/*
Expand Down
Loading