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

feat: input should blur when click other target. #1052

Merged
merged 17 commits into from Jan 6, 2022
Merged

Conversation

answershuto
Copy link
Member

@answershuto answershuto commented Jan 5, 2022

  • input 点击其他区域失焦
  • 修改 input placeholder 颜色

: super(context, defaultStyle: defaultStyle);
: super(context, defaultStyle: defaultStyle) {
// Since the bubbling process is in bridge, we need to globally hijack click for focus shifting, so you need to listen here.
addEvent('click');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样有没有副作用?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有,这个是增加方法注册使 gestureManager 判断整个 hittest 链路上有节点在监听,否则会被直接优化掉不执行。

@@ -222,6 +222,7 @@ class InputElement extends Element implements TextInputClient, TickerProvider {
// TODO: support ::placeholder pseudo element
return _buildTextSpan(
text: placeholderText,
color: Color.fromARGB(255, 169, 169, 169)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

设置一个常量吧, 或者注释说明一下

@@ -287,6 +287,9 @@ abstract class Node extends EventTarget implements RenderObjectNode, LifecycleCa
ownerDocument.gestureListener?.onTouchEnd!(event as TouchEvent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的判断写法可以一起改

void shiftFocus(EventTarget target) {
InputElement? inputElement = InputElement.focusInputElement;
if (inputElement != null && inputElement != target) {
InputElement.focusInputElement?.blur();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inputElement.blur();

@@ -895,6 +902,13 @@ class KrakenController {
}
}

void dispatchEvent(Event event) {
EventTarget? target = event.target;
if (event.type == 'click' && target != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'click' 使用常量代替

@@ -193,6 +193,13 @@ class KrakenViewController
late Document document;
late Window window;

void shiftFocus(EventTarget target) {
InputElement? inputElement = InputElement.focusInputElement;
if (inputElement != null && inputElement != target) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个加个 TODO 好了,未来如果有其他 element 也能获取焦点,这里的逻辑要改

wssgcg1213
wssgcg1213 previously approved these changes Jan 6, 2022
@wssgcg1213 wssgcg1213 merged commit ffadca3 into main Jan 6, 2022
@wssgcg1213 wssgcg1213 deleted the feat/input_blur branch January 6, 2022 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants