Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep todo item selected when checked/unchecked #19168

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 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 All @@ -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"
)}
<ha-svg-icon
slot="graphic"
Expand Down Expand Up @@ -466,18 +469,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
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
Expand Down
Loading