From 3831631f0a53afec66f628d8fa03ec4b0130cabc Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Mon, 31 Dec 2018 15:39:12 +0100 Subject: [PATCH] input: restore validate on tab key, select whole value on focus, adjust color hints --- CHANGELOG.md | 5 +++++ src/client/app/widgets/inputs/input.js | 12 ++++++++---- src/scss/widgets/inputs.scss | 6 +++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcfcdd5b..4db0246b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/client/app/widgets/inputs/input.js b/src/client/app/widgets/inputs/input.js index 5bf6f40a..4c85419d 100644 --- a/src/client/app/widgets/inputs/input.js +++ b/src/client/app/widgets/inputs/input.js @@ -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`` 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) { diff --git a/src/scss/widgets/inputs.scss b/src/scss/widgets/inputs.scss index 41b25eca..8bb707dd 100644 --- a/src/scss/widgets/inputs.scss +++ b/src/scss/widgets/inputs.scss @@ -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 {