From 1916dff57bbb2cfbb67bb21f554bb1c56ae3efa0 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 28 Dec 2023 15:32:40 +0100 Subject: [PATCH] Keep todo item selected when checked/unchecked (#19168) * Keep todo item selected when checked/unchecked * update label when in reoder mode --- .../lovelace/cards/hui-todo-list-card.ts | 22 +++++++++++++++---- src/panels/todo/dialog-todo-item-editor.ts | 1 - src/translations/en.json | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/panels/lovelace/cards/hui-todo-list-card.ts b/src/panels/lovelace/cards/hui-todo-list-card.ts index 6dbc1c8150..6c8e75e3b1 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" @@ -248,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" )} { 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 6e50995e9e..5206bfe8a8 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 diff --git a/src/translations/en.json b/src/translations/en.json index 1e498b7ac4..0209a3ffb7 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4768,6 +4768,7 @@ "add_item": "Add item", "today": "Today", "reorder_items": "Reorder items", + "exit_reorder_items": "Exit reorder mode", "drag_and_drop": "Drag and drop", "delete_item": "Delete item", "delete_confirm_title": "Remove completed items?",