Skip to content

Commit

Permalink
Merge pull request #626 from openkraken/fix/input-change-event
Browse files Browse the repository at this point in the history
fix: input change event
  • Loading branch information
answershuto authored Aug 24, 2021
2 parents 1780165 + be3b34b commit 794bb73
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
22 changes: 22 additions & 0 deletions integration_tests/specs/dom/elements/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,28 @@ describe('Tags input', () => {
});
});

it('event change', (done) => {
const VALUE = 'Input 3';
const input1 = document.createElement('input');
const input2 = document.createElement('input');
input1.setAttribute('value', 'Input 1');
input2.setAttribute('value', 'Input 2');
document.body.appendChild(input1);
document.body.appendChild(input2);

input1.addEventListener('change', function handler(event) {
expect(input1.value).toEqual(VALUE);
done();
});

input1.focus();

requestAnimationFrame(() => {
input1.setAttribute('value', VALUE);
input2.focus();
});
});

it('support inputmode=text', (done) => {
const VALUE = 'Hello';
const input = <input inputmode="text" />;
Expand Down
7 changes: 4 additions & 3 deletions kraken/lib/src/dom/elements/input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class InputElement extends Element implements TextInputClient, TickerProvider {
// Set focus that make it add keyboard listener
_renderEditable!.hasFocus = true;
activeTextInput();
dispatchEvent(Event('focus'));
dispatchEvent(Event(EVENT_FOCUS));
}
}

Expand All @@ -345,7 +345,9 @@ class InputElement extends Element implements TextInputClient, TickerProvider {
// Set focus that make it remove keyboard listener
_renderEditable!.hasFocus = false;
deactiveTextInput();
dispatchEvent(Event('blur'));
dispatchEvent(Event(EVENT_BLUR));
// Trigger change event if value has changed.
_triggerChangeEvent();
}
}

Expand Down Expand Up @@ -446,7 +448,6 @@ class InputElement extends Element implements TextInputClient, TickerProvider {
void performAction(TextInputAction action) {
switch (action) {
case TextInputAction.done:
_triggerChangeEvent();
InputElement.clearFocus();
break;
case TextInputAction.none:
Expand Down
1 change: 1 addition & 0 deletions kraken/lib/src/dom/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const String EVENT_TRANSITION_CANCEL = 'transitioncancel';
const String EVENT_TRANSITION_START = 'transitionstart';
const String EVENT_TRANSITION_END = 'transitionend';
const String EVENT_FOCUS = 'focus';
const String EVENT_BLUR = 'blur';
const String EVENT_LOAD = 'load';
const String EVENT_DOM_CONTENT_LOADED = 'DOMContentLoaded';
const String EVENT_UNLOAD = 'unload';
Expand Down

0 comments on commit 794bb73

Please sign in to comment.