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
Conversation
answershuto
commented
Jan 5, 2022
•
edited
edited
- 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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这样有没有副作用?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
设置一个常量吧, 或者注释说明一下
kraken/lib/src/dom/node.dart
Outdated
@@ -287,6 +287,9 @@ abstract class Node extends EventTarget implements RenderObjectNode, LifecycleCa | |||
ownerDocument.gestureListener?.onTouchEnd!(event as TouchEvent); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个加个 TODO 好了,未来如果有其他 element 也能获取焦点,这里的逻辑要改