Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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/orange-eyes-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@db-ux/ngx-core-components": patch
---

DBInput: inserting an empty string doesn't reset/empty date or time related form fields
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ showcases/patternhub/public/iframe-resizer/*
/packages/agent-cli/test/.amazonq/rules/db-ux.md
/core-web.iml
/build-storybooks/
blob-report/
2 changes: 1 addition & 1 deletion packages/components/scripts/post-build/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export const getComponents = (): Component[] => [
from: 'writeValue(value: any) {',
to:
'writeValue(value: any) {\n' +
'if (!value && (this.type() === "date" ||\n' +
'if (!value && value !== "" && (this.type() === "date" ||\n' +
' this.type() === "time" ||\n' +
' this.type() === "week" ||\n' +
' this.type() === "month" ||\n' +
Expand Down
30 changes: 30 additions & 0 deletions packages/components/src/components/input/input.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,36 @@ const testAction = () => {
await expect(input).not.toHaveAttribute('enterkeyhint');
await expect(input).not.toHaveAttribute('inputmode');
});

test('should clear date input when value is set to empty string', async ({
mount,
page
}) => {
const component = await mount(
<DBInput label="Date" type="date" value="2025-01-15" />
);
const input = page.locator('input[type="date"]');

// Verify initial value is set
await expect(input).toHaveValue('2025-01-15');

// Update component with empty string value
await component.evaluate((node: any, newValue: string) => {
const inputElement = node.querySelector('input');
if (inputElement) {
inputElement.value = newValue;
inputElement.dispatchEvent(
new Event('input', { bubbles: true })
);
inputElement.dispatchEvent(
new Event('change', { bubbles: true })
);
}
}, '');

// Verify the input is cleared
await expect(input).toHaveValue('');
});
};

test.describe('DBInput', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class FormComponent {
this.model.checkbox2 = false;
this.form.get('input')?.setValue('reset');
this.form.get('textarea')?.setValue('reset');
this.form.get('dateinput')?.setValue('reset');
this.form.get('dateinput')?.setValue('');
this.form.get('checkbox')?.setValue(false);
}

Expand Down