-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
add h5number type for inputItem #1419
Conversation
@pingan1927, thanks for your PR! By analyzing the history of the files in this pull request, we identified @chinalife, @warmhug and @silentcloud to be potential reviewers. |
Codecov Report
@@ Coverage Diff @@
## master #1419 +/- ##
=========================================
+ Coverage 61.98% 62.1% +0.12%
=========================================
Files 220 222 +2
Lines 4201 4455 +254
Branches 1236 1327 +91
=========================================
+ Hits 2604 2767 +163
- Misses 1596 1687 +91
Partials 1 1
Continue to review full report at Codecov.
|
<table> | ||
<tbody> | ||
<tr> | ||
<KeyboardItem onClick={this.onKeyBoardClick}>1</KeyboardItem> |
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.
这么多重复代码,优化一下?可以用function来创建重复的元素
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.
就这样吧,有的要设置rowspan 有的要设置特定className 有个一行4个元素 有的一行3个元素,function创建还要加一堆判断。
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.
这块改了
我们的 Icon 不都是用 svg 么,这里为啥是 png? |
<table> | ||
<tbody> | ||
<tr> | ||
<KeyboardItem onClick={this.onKeyBoardClick}>1</KeyboardItem> |
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.
同意,这里可以优化一下
components/input-item/index.web.tsx
Outdated
@@ -4,6 +4,7 @@ import classNames from 'classnames'; | |||
import omit from 'omit.js'; | |||
import InputItemProps from './PropsType'; | |||
import Input from './Input.web'; | |||
import H5NumberInput from './H5NumberInput.web'; |
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.
这里还是我们没有按需加载的问题,bundle体积会增大
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.
这个我也考虑过,子组件构建时不会搞进来? 比如Checkbox
和 Checkbox.CheckboxItem
,如果没有用到CheckboxItem
,相关代码不会引入?
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.
不是那样的, 是类似 import h5Input from 'antd-mobile/lib/input/h5input'
这个算是一个锦上添花功能,因为不是必须,只有用到这个场景了才需要,最好是做成 InputItem 的一个子组件来搞,不内置在 InputItem 里 @pingan1927 |
if (value === '') { | ||
onChange({ target: { value: '' } }); | ||
} else { | ||
onChange({ target: { value: value.substring(0, value.length - 1) } }); |
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.
这里不需要 if else的,else里的逻辑就够了
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.
改了!
onBlur={this.onInputBlur} | ||
disabled={disabled} | ||
value={fixControlledValue(value)} | ||
{...(this.props.focused !== undefined ? { focused: this.props.focused } : {})} |
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.
这里意图是要区分 !(focused in this.props)
和 this.props.focused === undefined
这两种情况?
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.
对
document.addEventListener('click', (ev) => { | ||
if (this.refs['input-container'] !== ev.target && | ||
this.refs['input-container'] !== (ev.target as any).closest(`.${prefixCls}-control`) && | ||
(ev.target as any).closest(`.${keyboardPrefixCls}-wrapper`) === 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.
我理解这里意图是要区分点击是否发生在虚拟键盘区域,
在虚拟键盘的最外层 div 上 stopPropagation, 再直接监听 document 上的 click,是否就可以认为此时的 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.
有两处,如果点击了 输入框以及对应的虚拟键盘外的地方 就触发onBlur。
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.
我理解 点击了 输入框以及对应的虚拟键盘外的地方
就是一种 点击了当前虚拟键盘之外的区域
。
所以建议尝试一下 stopPropagation 的方案
import H5NumberKeyBoard from './H5NumberKeyBoard'; | ||
|
||
if ((window as any).Element && !Element.prototype.closest) { | ||
Element.prototype.closest = |
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.
我的观点,同下面所讨论的 stopPropagation 方案,需要遍历 dom 的,甚至要 polyfill dom api的,应该是最后的选择,优先看其他方案。
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.
这段能不能移到 componentDidMount 里面去。
或者不碰 prototype,就写个函数 function closest(el, s)
,因为下面只有一处用到这个 closest 功能。
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.
@cncolder 这个我再重点考虑下,目前的PR放出来就是让讨论有的放矢。
这两个native的都是png,td里套svg不知道会不会带来麻烦(包div后垂直居中很难搞),我在斟酌下。不引入其他组件的前提下可以搞成svg。 |
[`${prefixCls}-wrapper-hide`]: hide, | ||
}); | ||
return (<div className={wrapperCls}> | ||
<table> |
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.
用 table 是为了布局考虑? Flex 应该很容易实现宫格布局吧,类似我们的 Grid
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.
用table
标签是最佳方案,rowspan
等参数就是为这个场景设置的。
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.
好吧.. 用 rowspan 来做这个 button 的布局的确挺巧妙的。
components/input-item/demo/money.md
Outdated
placeholder="money keyboard" | ||
clear | ||
maxLength={10} | ||
autoFocus |
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.
这个demo就不要 autoFocus了, 其他demo里也有个autoFocus, 真机上会同时弹出两个键盘
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.
是该去掉
> | ||
{value} | ||
</div> | ||
<CustomKeyboard |
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.
这里会导致一个页面可能有多个键盘实例,dom 冗余不说,事件也就会有多重绑定了。
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.
键盘的 dom 应该是仅仅只有一次,一个页面也只能同时准许弹出一个键盘实例
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.
这个也是一个纠结点,类似的共享模块的实现有没有,有就用,没有就初始化一个,虚拟键盘实例绑定在window对象?但这也破坏了组件的内聚性了
confirmDisabled: false, | ||
}; | ||
onKeyboardClick = (e, value) => { | ||
e.stopPropagation(); |
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.
这里改成 e.nativeEvent.stopImmediatePropagation();
同时在 onFakeInputClick
里也加上 e.nativeEvent.stopImmediatePropagation();
document on click 里面的那些 closet 读取 dom 的逻辑都可以去掉了
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.
if (autoFocus || focused) { | ||
this.onInputFocus(value); | ||
} | ||
document.addEventListener('click', (ev) => { |
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.
componentWillUnmount 里面删除事件,避免内存泄露。
import React from 'react'; | ||
import CustomKeyboard from './CustomKeyboard.web'; | ||
|
||
if ((window as any).Element && !Element.prototype.closest) { |
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.
这个 window 是在 require 阶段引用的,node 环境没法 require 这个文件。
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.
@cncolder 看我上面的评论,阻止冒泡的方法不需要再 polyfill closest, 这段代码可以删除
真机上体验下来还是有些问题的:
|
这个放弃,不支持。现在JSAPI里的实现也有bug。
金额键盘的核心功能是可以支持小数点输入,其他的都是次要需求。如果后续长按快速删除的需求特别强烈,我们再继续优化。
这个你是极端测试吧,H5的体验就是会差一点。 再次强调一点,核心需求是提供带小数点的数字键盘,不需要用户自己切换键盘,且不能输入其他字符。 |
* add h5number type for inputItem * fix bug for h5number input * optimize * fix name error * optimize code * optimize code
close #1383 #950 #349 ...
First of all, thanks for your contribution! :-)
Please makes sure these boxes are checked before submitting your PR, thank you!
npm run lint
and fix those errors before submitting in order to keep consistent code style.This change is