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: input change event #626

Merged
merged 2 commits into from
Aug 24, 2021
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
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