Skip to content

Commit

Permalink
Keep todo item selected when checked/unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Dec 28, 2023
1 parent 5b11e0c commit a583376
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/panels/lovelace/cards/hui-todo-list-card.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "@material/mwc-list/mwc-list";
import type { List } from "@material/mwc-list/mwc-list";
import {
mdiClock,
mdiDelete,
Expand Down Expand Up @@ -229,7 +230,7 @@ export class HuiTodoListCard extends LitElement implements LovelaceCard {
: nothing}
</div>
${uncheckedItems.length
? html` <div class="header">
? html`<div class="header">
<span>
${this.hass!.localize(
"ui.panel.lovelace.cards.todo-list.unchecked_items"
Expand Down Expand Up @@ -466,18 +467,29 @@ export class HuiTodoListCard extends LitElement implements LovelaceCard {
});
}

private _completeItem(ev): void {
private async _completeItem(ev): Promise<void> {
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<void> {
Expand Down
1 change: 0 additions & 1 deletion src/panels/todo/dialog-todo-item-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class DialogTodoItemEditor extends LitElement {
open
@closed=${this.closeDialog}
scrimClickAction
escapeKeyAction
.heading=${createCloseHeading(
this.hass,
isCreate
Expand Down

0 comments on commit a583376

Please sign in to comment.