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

Feature request: Optionally disable popping of items on backspace keydown #550

Closed
r-zane-spalding opened this issue Mar 7, 2022 · 3 comments · Fixed by r-zane-spalding/react-dropdown-tree-select#1 or #551
Labels

Comments

@r-zane-spalding
Copy link
Contributor

r-zane-spalding commented Mar 7, 2022

Is your feature request related to a problem? Please describe.
Users are getting confused when trying to clear search filters with backspace and accidentally deselecting items. Using backspace on an empty search bar to deselect items doesn't seem to be expected behavior for most people.

Describe the solution you'd like
Add a prop disablePoppingOnBackspace that defaults to false but is able to turn off this behavior.

Describe alternatives you've considered
Alternative could be disable by default and enable optionally but this would change existing behavior and likely wouldn't be ideal.

Additional context

//index.js

static propTypes = {
  //...
  tabIndex: PropTypes.number,
  disablePoppingOnBackspace: PropTypes.bool,
}

onKeyboardKeyDown = e => {
  //...
  } else if (!disablePoppingOnBackspace && e.key === 'Backspace' && tags.length && this.searchInput.value.length === 0) {
    const lastTag = tags.pop()
    this.onCheckboxChange(lastTag._id, false)
  } else {
    return
  }
  e.preventDefault()
}

//index.test.js
test('cannot delete tags on empty search input with backspace on keyboardNavigation with disablePoppingOnBackspace enabled', t => {
  const data = [{ ...node('a', 'a'), checked: true }, { ...node('b', 'b'), checked: true }]
  const wrapper = mount(<DropdownTreeSelect data={data} disablePoppingOnBackspace={true}/>)
  wrapper.instance().searchInput.value = 'x'
  triggerOnKeyboardKeyDown(wrapper, 'Backspace')
  t.deepEqual(wrapper.state().tags.length, 2)

  wrapper.instance().searchInput.value = ''
  triggerOnKeyboardKeyDown(wrapper, 'Backspace')
  t.deepEqual(wrapper.state().tags.length, 2)
  triggerOnKeyboardKeyDown(wrapper, 'Backspace')
  t.deepEqual(wrapper.state().tags.length, 2)
})
@mrchief
Copy link
Collaborator

mrchief commented Mar 7, 2022

@r-zane-spalding thanks for the suggestion and filling out the details. This is a good idea, and your code looks sound. Would you mind sending a PR? We'd also need to add this to the docs.

@r-zane-spalding
Copy link
Contributor Author

r-zane-spalding commented Mar 7, 2022

Sure, I'll have that in shortly. Thanks for the response!

edit: PR here

@github-actions
Copy link

github-actions bot commented Mar 7, 2022

🎉 This issue has been resolved in version 2.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants