Skip to content

Conversation

@Jayesh2812
Copy link

The user can now press Backspace at start of the TODO to do one of the following

  1. If the TODO is empty, delete the item.
  2. If the TODO is not empty combine TODO's name with previous TODO's name.

#37 issue will be fixed by merging this pull request.

setItemText(items[itemIndex].name);
}, [changeFocus, focus, itemIndex, items]);

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One useEffect above already doing the same. Can you remove it?

}, [items[itemIndex].name]);

const handleDelete = () => {
items.splice(itemIndex, 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before changing the items array. Create a copy of items to avoid reference changes directly. You can do something like this.

const itemsCopy = [...items];
itemsCopy.splice(itemIndex, 1);
setItemsCallback([...itemsCopy]);


if (inputRef.current!.selectionStart) return; // Do nothing if cursor isn't at start.

let previousItemElement = getNthTodoElement(itemIndex - 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the predefined setFocus function to focus the element. If you need a selection as well you can add one more method to setSelection. That you can do in different PR if needed.


const handleArrowKey : KeyboardEventHandler<HTMLDivElement> = (e) => {
const inputs = document.querySelectorAll("input[type='text']");
const inputsArray = Array.from(inputs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again try to do the same using the setFocus method.

@Jayesh2812
Copy link
Author

I was out of town for few days, will start working on the changes this week. Thank you so much for the reviews and suggestions 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants