Closed yeswanthannadata closed 1 year ago
@yeswanthannadata Your implementation looks good on the current code. But if you see the focus logic is broken.
useEffect(() => {
items[itemIndex].name.length < 2 &&
inputRef.current &&
inputRef.current.focus();
setItemText(items[itemIndex].name);
}, []);
It will focus on the first element length < 2. Can you fix that as a separate PR? In place of a length check, you can use a variable to control the current focus element.
Then you can simplify the current PR. the logic becomes simple like this. No need to use pushMeta
.
const text = itemTitle.slice(0, cursorPosition);
setItemText(itemTitle.slice(cursorPosition, itemTitle.length));
addItem({ name: text, uuid: uuid(), isComplete: false });
setFocus(itemIndex+1);
@yeswanthannadata Thanks for your efforts. I have created a new ticket you can also pick this https://github.com/upnotes-io/react-todo/issues/30 as you already know things around the focus. Just add a comment on the ticket if you want to work on this.
I am closing this due to a lack of activity. @yeswanthannadata Please raise a new PR if you want to continue.
Implemented the enter press event in different scenarios as mentioned over the issue. Please review and reach out to me for any changes needed.