Skip to content

Commit

Permalink
Add support for Enter & Esc when creating new things
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischrischris committed Mar 28, 2024
1 parent f44d367 commit 7783c5b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion blocks/browse/da-browse/da-browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ export default class DaBrowse extends LitElement {
return null;
}

handleKeyCommands(event) {
if (event.key === 'Enter') {
event.preventDefault();
this.handleSave();
} else if (event.key === 'Escape') {
this.resetCreate();
}
}

renderNew() {
return html`
<div class="da-actions-create ${this._createShow}">
Expand All @@ -257,7 +266,7 @@ export default class DaBrowse extends LitElement {
</li>
</ul>
<div class="da-actions-input-container">
<input type="text" class="da-actions-input" placeholder="Name" @input=${this.handleNameChange} .value=${this._createName} />
<input type="text" class="da-actions-input" placeholder="Name" @input=${this.handleNameChange} .value=${this._createName} @keydown=${this.handleKeyCommands}/>
<button class="da-actions-button" @click=${this.handleSave}>Create ${this._createType}</button>
<button class="da-actions-button da-actions-button-cancel" @click=${this.resetCreate}>Cancel</button>
</div>
Expand Down

0 comments on commit 7783c5b

Please sign in to comment.