From a58337692b55d75cf1151c0ddf96d2ad6880e0f8 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 28 Dec 2023 14:17:32 +0100 Subject: [PATCH 1/2] Keep todo item selected when checked/unchecked --- .../lovelace/cards/hui-todo-list-card.ts | 18 +++++++++++++++--- src/panels/todo/dialog-todo-item-editor.ts | 1 - 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/panels/lovelace/cards/hui-todo-list-card.ts b/src/panels/lovelace/cards/hui-todo-list-card.ts index 6dbc1c815006..b084b5681fb8 100644 --- a/src/panels/lovelace/cards/hui-todo-list-card.ts +++ b/src/panels/lovelace/cards/hui-todo-list-card.ts @@ -1,4 +1,5 @@ import "@material/mwc-list/mwc-list"; +import type { List } from "@material/mwc-list/mwc-list"; import { mdiClock, mdiDelete, @@ -229,7 +230,7 @@ export class HuiTodoListCard extends LitElement implements LovelaceCard { : nothing} ${uncheckedItems.length - ? html`
+ ? html`
${this.hass!.localize( "ui.panel.lovelace.cards.todo-list.unchecked_items" @@ -466,18 +467,29 @@ export class HuiTodoListCard extends LitElement implements LovelaceCard { }); } - private _completeItem(ev): void { + private async _completeItem(ev): Promise { const item = this._getItem(ev.currentTarget.itemId); if (!item) { return; } - updateItem(this.hass!, this._entityId!, { + await updateItem(this.hass!, this._entityId!, { ...item, status: item.status === TodoItemStatus.NeedsAction ? TodoItemStatus.Completed : TodoItemStatus.NeedsAction, }); + await this.updateComplete; + const newList: List = this.shadowRoot!.querySelector( + item.status === TodoItemStatus.NeedsAction ? "#checked" : "#unchecked" + )!; + await newList.updateComplete; + const items = + item.status === TodoItemStatus.NeedsAction + ? this._getCheckedItems(this._items) + : this._getUncheckedItems(this._items); + const index = items.findIndex((itm) => itm.uid === item.uid); + newList.focusItemAtIndex(index); } private async _clearCompletedItems(): Promise { diff --git a/src/panels/todo/dialog-todo-item-editor.ts b/src/panels/todo/dialog-todo-item-editor.ts index 6e50995e9ec3..5206bfe8a877 100644 --- a/src/panels/todo/dialog-todo-item-editor.ts +++ b/src/panels/todo/dialog-todo-item-editor.ts @@ -99,7 +99,6 @@ class DialogTodoItemEditor extends LitElement { open @closed=${this.closeDialog} scrimClickAction - escapeKeyAction .heading=${createCloseHeading( this.hass, isCreate From c7279bb2f7df7e299fb81ce524da1c5502e9521d Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 28 Dec 2023 14:22:12 +0100 Subject: [PATCH 2/2] update label when in reoder mode --- src/panels/lovelace/cards/hui-todo-list-card.ts | 4 +++- src/translations/en.json | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/panels/lovelace/cards/hui-todo-list-card.ts b/src/panels/lovelace/cards/hui-todo-list-card.ts index b084b5681fb8..6c8e75e3b1f9 100644 --- a/src/panels/lovelace/cards/hui-todo-list-card.ts +++ b/src/panels/lovelace/cards/hui-todo-list-card.ts @@ -249,7 +249,9 @@ export class HuiTodoListCard extends LitElement implements LovelaceCard { graphic="icon" > ${this.hass!.localize( - "ui.panel.lovelace.cards.todo-list.reorder_items" + this._reordering + ? "ui.panel.lovelace.cards.todo-list.exit_reorder_items" + : "ui.panel.lovelace.cards.todo-list.reorder_items" )}