Skip to content

Commit 77210bb

Browse files
authored
Merge pull request #142 from fleetbase/dev-v0.3.41
Fix DateTimeInput controlled editing
2 parents f2e0c47 + c61864f commit 77210bb

4 files changed

Lines changed: 32 additions & 21 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="ui-date-time-input grid grid-cols-2 gap-2" {{did-update this.updateValue @value}} ...attributes>
1+
<div class="ui-date-time-input grid grid-cols-2 gap-2" ...attributes>
22
<Input @type="date" @value={{this.date}} min={{@minDate}} max={{@maxDate}} aria-label="Date Input" class="border-0 m-0 p-0 bg-transparent" {{on "input" (fn this.update "date")}} />
33
<Input @type="time" @value={{this.time}} min={{@minTime}} max={{@maxTime}} aria-label="Time Input" class="border-0 m-0 p-0 bg-transparent" {{on "input" (fn this.update "time")}} />
44
</div>

addon/components/date-time-input.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ export default class DateTimeInputComponent extends Component {
5555
return null;
5656
}
5757

58-
@action updateValue(value) {
59-
this.syncValue(value);
60-
}
61-
6258
/**
6359
* Update component value.
6460
*
@@ -85,14 +81,6 @@ export default class DateTimeInputComponent extends Component {
8581
}
8682

8783
if (!dateTimeInstance || !isValid(dateTimeInstance)) {
88-
if (typeof onUpdate === 'function') {
89-
onUpdate(null, null);
90-
}
91-
92-
if (typeof onChange === 'function') {
93-
onChange(null, null);
94-
}
95-
9684
return;
9785
}
9886

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fleetbase/ember-ui",
3-
"version": "0.3.40",
3+
"version": "0.3.41",
44
"description": "Fleetbase UI provides all the interface components, helpers, services and utilities for building a Fleetbase extension into the Console.",
55
"keywords": [
66
"fleetbase-ui",

tests/integration/components/date-time-input-test.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { module, test } from 'qunit';
22
import { setupRenderingTest } from 'dummy/tests/helpers';
3-
import { fillIn, render, settled } from '@ember/test-helpers';
3+
import { fillIn, render } from '@ember/test-helpers';
44
import { hbs } from 'ember-cli-htmlbars';
55

66
module('Integration | Component | date-time-input', function (hooks) {
@@ -108,15 +108,38 @@ module('Integration | Component | date-time-input', function (hooks) {
108108
await fillIn('[aria-label="Time Input"]', '19:12');
109109
});
110110

111-
test('it syncs when the external value changes', async function (assert) {
111+
test('it does not reset while controlled by a parent value', async function (assert) {
112+
assert.expect(4);
113+
112114
this.set('value', '2026-06-18 18:47');
115+
this.set('onUpdate', (dateTimeInstance) => {
116+
this.set('value', dateTimeInstance);
117+
});
113118

114-
await render(hbs`<DateTimeInput @value={{this.value}} />`);
119+
await render(hbs`<DateTimeInput @value={{this.value}} @onUpdate={{this.onUpdate}} />`);
115120

116-
this.set('value', '2026-07-03T15:00:00+08:00');
117-
await settled();
121+
await fillIn('[aria-label="Date Input"]', '2026-06-19');
118122

119-
assert.dom('[aria-label="Date Input"]').hasValue('2026-07-03');
120-
assert.dom('[aria-label="Time Input"]').hasValue('15:00');
123+
assert.dom('[aria-label="Date Input"]').hasValue('2026-06-19');
124+
assert.dom('[aria-label="Time Input"]').hasValue('18:47');
125+
126+
await fillIn('[aria-label="Time Input"]', '19:12');
127+
128+
assert.dom('[aria-label="Date Input"]').hasValue('2026-06-19');
129+
assert.dom('[aria-label="Time Input"]').hasValue('19:12');
130+
});
131+
132+
test('it does not emit null while native inputs are incomplete', async function (assert) {
133+
assert.expect(1);
134+
135+
this.set('value', '2026-06-18 18:47');
136+
this.set('onUpdate', () => {
137+
assert.ok(false, 'onUpdate should not be called for incomplete input');
138+
});
139+
140+
await render(hbs`<DateTimeInput @value={{this.value}} @onUpdate={{this.onUpdate}} />`);
141+
await fillIn('[aria-label="Date Input"]', '');
142+
143+
assert.dom('[aria-label="Date Input"]').hasValue('');
121144
});
122145
});

0 commit comments

Comments
 (0)