-
Notifications
You must be signed in to change notification settings - Fork 563
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
Allow unselecting tags by keyboard #1853
Allow unselecting tags by keyboard #1853
Conversation
Just realized I forgot about the tab key! I'll add that in in a second. I figure I'll leave the right arrow control in as well, that's the way that I would naturally think to exit the tag chip. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @qualitymanifest - this is awesome work!
In looking at interceptKeys
though it's clear that it was intended to prevent this very issue but for some reason that's not working. Although in testing it's clear that your patch fixes the issue at hand, I think the cause remains unresolved - merely worked-around.
In tag-input/index.tsx
we can see that we only seem to call onChange
during significant keyboard events vs. as the tag is being typed. Because of that we don't update this.state.tagInput
in tag-field/index.tsx
and our check '' !== this.state.tagInput
never catches.
Do you think you might be interested in addressing the exchange between tag-field
and tag-input
? If we do that then we won't have to duplicate the logic.
We're happy to have your contributions so don't worry if you don't have time; I just want to make sure that we fix the problem where it originates.
I could definitely be missing something though! |
@qualitymanifest what I was seeing at a cursory glance was that we only seem to be sending the updated tag text from in other words, both components should agree that the input text is |
@dmsnell From my understanding, That being said - it seems unrelated to the issue of being able to key out of a tag-chip. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience while I reviewed this @qualitymanifest. Everything you wrote seems sound and in testing worked just like you said.
There are some changes I'd like to apply to account for styling in the app and I couldn't remember how to update this PR directly so I was wondering if you'd be willing to apply this patch and push it out on the branch.
diff --git a/lib/tag-field/index.tsx b/lib/tag-field/index.tsx
index 2158790..55b9636 100644
--- a/lib/tag-field/index.tsx
+++ b/lib/tag-field/index.tsx
@@ -1,4 +1,4 @@
-import React, { Component } from 'react';
+import React, { Component, KeyboardEventHandler } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { Overlay } from 'react-overlays';
@@ -18,6 +18,10 @@ import {
union,
} from 'lodash';
+const KEY_BACKSPACE = 8;
+const KEY_TAB = 9;
+const KEY_RIGHT = 39;
+
export class TagField extends Component {
static displayName = 'TagField';
@@ -113,9 +117,8 @@ export class TagField extends Component {
focusTagField = () => this.focusInput && this.focusInput();
- interceptKeys = e => {
- // handle backspace
- if (8 === e.which) {
+ interceptKeys: KeyboardEventHandler<HTMLDivElement> = e => {
+ if (KEY_BACKSPACE === e.which) {
if (this.hasSelection()) {
this.deleteSelection();
}
@@ -126,15 +129,18 @@ export class TagField extends Component {
this.selectLastTag();
e.preventDefault();
+ return;
}
- // handle right arrow
- else if (39 === e.which && this.hasSelection()) {
+
+ if (KEY_RIGHT === e.which && this.hasSelection()) {
this.unselect(e);
this.focusTagField();
+ return;
}
- // handle tab
- else if (9 === e.which && this.hasSelection()) {
+
+ if (KEY_TAB === e.which && this.hasSelection()) {
this.unselect(e);
+ return;
}
};
Made the changes, reads a lot better with the constants @dmsnell |
Fix
Closes #1852
If a tag is selected and the right arrow key is pressed, the tag is unselected and the focus is moved back into the tag field.
Test
See the issue for details to reproduce, but use right arrow to unselect
Review
Only one developer is required to review these changes, but anyone can perform the review.
Release
Release notes updated in bde11cf