User Input: Can't Delete Search Terms with Keyboard
Bug Description
When I fill out search terms, I can't then delete them with the backspace/delete key.
Steps to reproduce
- Go to user input flow
- Get to 5/5 search terms
- Fill out some search terms
- Try and delete with backspace
- See that search terms don't get deleted
Screenshots
Additional Context
- PHP Version:
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Plugin Version [e.g. 22]
- Device: [e.g. iPhone6]
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- When pressing the backspace key within a search term (i.e. cursor is within the search term bubble), it should delete characters from that search term.
- When pressing the backspace key when right after a search term (i.e. the cursor is outside a search term bubble, right after one), it should delete that entire search term.
Implementation Brief
- Once #2842 has been merged, using
/assets/js/components/user-input/UserInputKeywords.js,- import
BACKSPACEfrom@wordpress/keycodes. - create new function
deleteKeywordwhich does the same thing asonKeywordDelete. - update
onKeywordDeleteto use thedeleteKeywordfunction. - update the
onKeyDownfunction to:- get the length of
nonEmptyValues - if the length is less than
3and theBACKSPACEkey is pressed, call thedeleteKeywordfunction passingnonEmptyValuesLength - 1as the index to delete. - set the focus to the input text again using the same logic when the
ENTERorCOMMAkeys are pressed, but this time, having the following selector:#${ slug }-keyword-${ nonEmptyValuesLength - 1 }
- get the length of
- import
Test Coverage
N/A
Visual Regression Changes
N/A
QA Brief
- Fill out the user input flow until you reach step 5 (search terms)
- You should be able to:
- Enter up to 3 words, pressing comma or enter/ return to enter a word
- Delete within a word you are typing (i.e. hitting backspace while typing a word should delete the character you have just typed)
- Delete a term after entering it (e.g. type
test, hit comma to enter it, thentesting, hitting comma again. Now hit the the backspace andtestingshould be removed, but nottest).
Changelog entry
- Fix accessibility problem where it wasn't possible to delete user input search terms using the keyboard.
IB largely looks good but one thing I'm not clear on:
if
nonEmptyValues.lengthis than3and theBACKSPACEkey is pressed, call thedeleteKeywordfunction passingnonEmptyValuesLength - 1as the index to delete.
Why does it matter if there are fewer than the max number of keywords entered? Isn't the idea that if you can focus the text field and backspace in an empty bubble/outside a bubble that it deletes no matter what?
I'd think this check would instead be if nonEmptyValues.length is 0—if that's the case we don't delete anything as there's nothing to delete.
@tofumatt As per the AC, When pressing the backspace key within a search term (i.e. cursor is within the search term bubble), it should delete characters from that search term. so if you are at the third item (max. number), if the backspace key is pressed, it should not delete the item, rather it should delete characters from that item.
Just realised this IB isn't finished, sorry! I'll pause work until it is passed review. My mistake 🙏
@asvinb Ah, okay, thanks! Makes sense now. 👍🏻
IB ✅
QA Update: Fail ❌
@johnPhillips when I hit backspace within a word, it will allow me to delete one letter but the cursor then jumps to the end of the word. This is an issue if I am wanting to delete more than one letter within the word. When I hit the backspace once, I should then be able to hit the key again to delete the next letter.
Right now, I have to click backspace once to delete the letter, and then click in the word again next to the next letter I want to delete, and hit backspace again. Here's a quick screencast
https://user-images.githubusercontent.com/73545194/113860473-ac0a0500-97d8-11eb-98fb-661ef1070e25.mp4
Verified:
Delete a term after entering it, is removed. (e.g. type test, hit comma to enter it, then testing, hitting comma again. Now hit the the backspace and testing is removed, but not test).
@johnPhillips and I chatted about this and turns out this was an issue even before this fix landed—the way we store the data for these elements in state and then select them causes a known bug with input cursor jumping with controlled components. I found a fix for this and will have a PR soon… it's arguably almost a separate issue but I'll fix it as part of the QA here. 🙂
QA Update: Pass ✅
On the 5th question, when you enter up to 3 words:
- User can delete letters within a word.
- User can delete a term after entering it.
- Also confirmed that these two tests in the QAB on mobile and tablet devices.
https://user-images.githubusercontent.com/73545194/114394439-c7588400-9bcd-11eb-8f6c-659ba1558671.mov