Skip to content

Commit

Permalink
feat(gv-expression-language): add support of autofocus attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
gcusnieux authored and tcompiegne committed Jun 15, 2021
1 parent d31702d commit 5bbfa95
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/mixins/input-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ export function InputElement(ParentClass) {

firstUpdated() {
if (this.autofocus) {
this.getInputElement().focus();
const input = this.getInputElement();
if (input != null) {
this.getInputElement().focus();
}
}
this.updateState(this.value);
}
Expand Down
6 changes: 6 additions & 0 deletions src/molecules/gv-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ export class GvCode extends InputElement(LitElement) {
},
});

if (this.autofocus) {
setTimeout(() => {
this._codeMirror.focus();
}, 200);
}

dispatchCustomEvent(this, 'ready');
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/molecules/gv-expression-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { dispatchCustomEvent } from '../lib/events';
* @attr {Number} rows - Number of rows, if rows=1 the field will look like an input text
* @attr {Object} options - options based on codemirror https://codemirror.net/doc/manual.html#config
* @attr {Boolean} inner-hint - Useful to force ineer rendering of "hint" element
* @attr {Boolean} [autofocus=false] - true to put the focus on the input
*/
export class GvExpressionLanguage extends LitElement {
static get properties() {
Expand All @@ -51,6 +52,7 @@ export class GvExpressionLanguage extends LitElement {
disabled: { type: Boolean, reflect: true },
required: { type: Boolean, reflect: true },
readonly: { type: Boolean, reflect: true },
autofocus: { type: Boolean },
innerHint: { type: Boolean, attribute: 'inner-hint' },
};
}
Expand Down Expand Up @@ -474,6 +476,7 @@ export class GvExpressionLanguage extends LitElement {
?disabled="${this.disabled}"
?readonly="${this.readonly}"
?required="${this.required}"
?autofocus="${this.autofocus}"
.placeholder="${this.placeholder}"
.description="${this.description}"
></gv-code>
Expand Down

0 comments on commit 5bbfa95

Please sign in to comment.