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

Do not print when typing Tab or Shift+Tab #51

Merged
merged 6 commits into from
Jun 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const ENTER = '\r';
const CTRL_C = '\x03';
const BACKSPACE = '\x08';
const DELETE = '\u007F';
const TAB = '\t';
const SHIFT_TAB = '\u001B[Z';

class TextInput extends PureComponent {
static propTypes = {
Expand Down Expand Up @@ -106,7 +108,7 @@ class TextInput extends PureComponent {

const s = String(data);

if (s === ARROW_UP || s === ARROW_DOWN || s === CTRL_C) {
if (s === ARROW_UP || s === ARROW_DOWN || s === CTRL_C || s === TAB || s === SHIFT_TAB) {
return;
}

Expand Down
15 changes: 15 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ test('ignore input when not in focus', t => {
t.is(frames.length, 1);
});

test('ignore input for Tab and Shift+Tab keys', t => {
const Test = () => {
const [value, setValue] = useState('');

return <TextInput value={value} onChange={setValue}/>;
};

const {stdin, lastFrame} = render(<Test/>);

stdin.write('\t');
t.is(lastFrame(), CURSOR);
stdin.write('\u001B[Z');
t.is(lastFrame(), CURSOR);
});

test('onSubmit', t => {
const onSubmit = sinon.spy();

Expand Down