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(core/button): replace workaround with element internals #1687

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/rare-tables-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siemens/ix': patch
---

Fix issue of `ix-button` which prevent a form get submitted twice in row.
9 changes: 9 additions & 0 deletions packages/core/src/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ export class Button implements IxButtonComponent {
}
}

componentDidRender() {
if (
this.submitButtonElement &&
!this.hostElement.contains(this.submitButtonElement)
) {
this.hostElement.appendChild(this.submitButtonElement);
}
}

dispatchFormEvents() {
if (
this.type === 'submit' &&
Expand Down
37 changes: 37 additions & 0 deletions packages/core/src/components/button/test/button.ct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test';

declare global {
interface Window {
submitCount: number;
}
}

test('renders', async ({ mount, page }) => {
await mount(`<ix-button>Content</ix-button>`);
const button = page.locator('ix-button');
Expand Down Expand Up @@ -59,3 +65,34 @@ test.describe('A11y', () => {
await expect(button).not.toHaveAttribute('aria-disabled');
});
});

test('form can be submitted multiple times', async ({ mount, page }) => {
await mount(`
<form id="test-form">
<input type="text" name="test-input" required minlength="1">
<ix-button type="submit">Submit</ix-button>
</form>
`);

await page.evaluate(() => {
const form = document.getElementById('test-form');
form?.addEventListener('submit', (e) => {
e.preventDefault();
window.submitCount = (window.submitCount || 0) + 1;
});
});

const button = page.locator('ix-button');
const input = page.locator('input[name="test-input"]');

for (let i = 0; i < 3; i++) {
await input.fill('test');
await button.click();
const submitCount = await page.evaluate(() => window.submitCount);
expect(submitCount).toBe(i + 1);
await page.waitForTimeout(100);
}

await expect(button).not.toHaveAttribute('disabled');
await expect(button).not.toHaveClass(/loading/);
});
Loading