input: restore validate on tab key, select whole value on focus, adjust color hints

This commit is contained in:
jean-emmanuel 2018-12-31 15:39:12 +01:00
parent 214a95e816
commit 3831631f0a
3 changed files with 18 additions and 5 deletions

View file

@ -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) {

View file

@ -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 {