-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Input): support froze value on input, close #389
- Loading branch information
Showing
5 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
title: 输入过程中禁止更新 | ||
order: 7 | ||
--- | ||
|
||
默认情况下`value`变化,就会更新视图的`value`值,但这会打断用户的输入,当添加`frozenOnInput`属性时,组件的`value` | ||
在输入的过程中被冻结,输入完成后,组件才会更新最新的`value`到视图 | ||
|
||
```vdt | ||
import {Input} from 'kpc/components/input'; | ||
<div> | ||
<Input value={{ self.get('value') }} ev-input={{ self._onInput }} /> | ||
<br /> | ||
<Input frozenOnInput value={{ self.get('value') }} ev-input={{ self._onInput }} /> | ||
</div> | ||
``` | ||
|
||
```styl | ||
.k-input | ||
margin 5px | ||
``` | ||
|
||
```js | ||
import tinycolor from 'tinycolor2'; | ||
|
||
export default class extends Intact { | ||
@Intact.template() | ||
static template = template; | ||
|
||
defaults() { | ||
return { | ||
value: '#ddd' | ||
}; | ||
} | ||
|
||
_onInput(e) { | ||
const value = e.target.value.trim(); | ||
const color = tinycolor(value); | ||
if (color.isValid()) { | ||
this.set('value', color.toHexString()); | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters