input: restore validate on tab key, select whole value on focus, adjust color hints
This commit is contained in:
parent
214a95e816
commit
3831631f0a
3 changed files with 18 additions and 5 deletions
|
|
@ -1,5 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## 0.40.5
|
||||
|
||||
- widgets
|
||||
- input: hitting `tab` now validates the value before focusing the next input (hitting `esc` or clicking outside the widget still cancels); when focusing an input widget, its whole value is selected by default; focused/selected text color hint changes.
|
||||
|
||||
## 0.40.4
|
||||
|
||||
- bug fixes
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ module.exports = class Input extends Canvas {
|
|||
this.value = ''
|
||||
this.stringValue = ''
|
||||
this.focused = false
|
||||
this.tabKeyBlur = false
|
||||
|
||||
if (this.getProp('vertical')) this.widget.classList.add('vertical')
|
||||
if (this.getProp('align') === 'left') this.widget.classList.add('left')
|
||||
|
|
@ -41,11 +42,13 @@ module.exports = class Input extends Canvas {
|
|||
this.canvas.addEventListener('focus', this.focus.bind(this))
|
||||
this.input = html`<input class="no-keybinding"></input>`
|
||||
this.input.addEventListener('blur', (e)=>{
|
||||
this.blur(false)
|
||||
this.blur(this.tabKeyBlur)
|
||||
this.tabKeyBlur = false
|
||||
})
|
||||
this.input.addEventListener('keydown', (e)=>{
|
||||
if (e.keyCode==13) this.blur()
|
||||
if (e.keyCode==27) this.blur(false)
|
||||
if (e.keyCode === 13) this.blur() // enter
|
||||
else if (e.keyCode === 27) this.blur(false) // esc
|
||||
else if (e.keyCode === 9) this.tabKeyBlur = true // tab
|
||||
})
|
||||
} else {
|
||||
this.widget.classList.add('not-editable')
|
||||
|
|
@ -62,7 +65,8 @@ module.exports = class Input extends Canvas {
|
|||
this.input.value = this.stringValue
|
||||
this.widget.insertBefore(this.input, this.canvas)
|
||||
this.input.focus()
|
||||
|
||||
this.input.setSelectionRange(0, this.input.value.length)
|
||||
|
||||
}
|
||||
|
||||
blur(change=true) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
display: flex;
|
||||
flex: 1 1 100%;
|
||||
background:transparent;
|
||||
color:var(--color-text-fade);
|
||||
color:var(--color-text);
|
||||
overflow: hidden;
|
||||
text-align:center;
|
||||
padding:1rem;
|
||||
|
|
@ -55,7 +55,11 @@
|
|||
-webkit-user-select: text;
|
||||
user-select: text;
|
||||
&:focus {
|
||||
color:var(--color-text-fade);
|
||||
}
|
||||
&:focus::selection {
|
||||
color:var(--color-custom);
|
||||
background: transparent;
|
||||
}
|
||||
}
|
||||
canvas {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue