Skip to content

Commit

Permalink
fix: reset input focus status when spec done.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Nov 20, 2022
1 parent 03b3f6f commit d26a928
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
3 changes: 2 additions & 1 deletion bridge/core/binding_call_methods.json5
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
"className",
"cookie",
"class",
"syncPropertiesAndMethods"
"syncPropertiesAndMethods",
"_clearFocus__"
]
}
1 change: 1 addition & 0 deletions bridge/core/html/forms/html_input_element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ interface HTMLInputElement extends HTMLElement {
inputMode: DartImpl<string>;
focus(): DartImpl<void>;
blur(): DartImpl<void>;
_clearFocus__(): DartImpl<void>;
new(): void;
}
14 changes: 14 additions & 0 deletions bridge/polyfill/src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,27 @@ class JasmineTracker {

specDone(result) {
clearAllTimer();
resetFocusState(document.body);
resetDocumentElement();
webf.methodChannel.clearMethodCallHandler();
}
specStarted(result) {
}
}

function resetFocusState(node) {
if (!node) return;
if (node._clearFocus__) {
node._clearFocus__();
}

if (node.childNodes && node.childNodes.length > 0) {
for(let i = 0; i < node.childNodes.length; i ++) {
resetFocusState(node.childNodes[i]);
}
}
}

const consoleReporter = new ConsoleReporter();
const jasmineTracker = new JasmineTracker();

Expand Down
15 changes: 10 additions & 5 deletions integration_tests/specs/dom/elements/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('Tags input', () => {
await snapshot();
});

fit('line-height set and is bigger than text size', async () => {
it('line-height set and is bigger than text size', async () => {
let input;
input = createElement(
'input',
Expand Down Expand Up @@ -256,7 +256,9 @@ describe('Tags input', () => {

requestAnimationFrame(() => {
input1.focus();
input2.focus();
requestAnimationFrame(() => {
input2.focus();
});
});
});

Expand All @@ -276,9 +278,10 @@ describe('Tags input', () => {

requestAnimationFrame(() => {
input1.focus();
input2.focus();
requestAnimationFrame(() => {
input2.focus();
});
});

});

it('event input', (done) => {
Expand All @@ -298,7 +301,9 @@ describe('Tags input', () => {
document.body.appendChild(input);
input.focus();
requestAnimationFrame(() => {
simulateInputText(VALUE);
requestAnimationFrame(() => {
simulateInputText(VALUE);
});
});
});

Expand Down
8 changes: 8 additions & 0 deletions webf/lib/src/html/input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class FlutterInputElement extends WidgetElement
methods['focus'] = BindingObjectMethodSync(call: (List args) {
focus();
});
if (kDebugMode) {
methods['_clearFocus__'] = BindingObjectMethodSync(call: (args) {
_focusNode.unfocus();
});
}
}

@override
Expand Down Expand Up @@ -318,9 +323,12 @@ mixin BaseInputElement on WidgetElement {
if (ownerDocument.focusedElement == this) {
ownerDocument.focusedElement = null;
}
// When the element loses focus after its value was changed: for elements where the user's interaction is typing rather than selection,
// such as a <textarea> or the text, search, url, tel, email, or password types of the <input> element
if (oldValue != value) {
dispatchEvent(Event('change'));
}

dispatchEvent(FocusEvent(EVENT_BLUR, relatedTarget: this));
}
}
Expand Down
2 changes: 1 addition & 1 deletion webf/lib/src/rendering/viewport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RenderViewportBox extends RenderBox
final ContainerBoxParentData<RenderObject> childParentData = child.parentData as ContainerBoxParentData<RenderObject>;

RenderBoxModel rootRenderLayoutBox = child as RenderLayoutBox;
child!.layout(rootRenderLayoutBox.getConstraints().tighten(width: width, height: height));
child.layout(rootRenderLayoutBox.getConstraints().tighten(width: width, height: height));

assert(child.parentData == childParentData);
child = childParentData.nextSibling;
Expand Down

0 comments on commit d26a928

Please sign in to comment.