Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
Closed
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
3 changes: 2 additions & 1 deletion example/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ const root = document.getElementById("root");
const initialSettings: ReactTagInputProps = {
tags: [],
onChange: (tags) => {},
placeholder: "Types and press enter",
placeholder: "Type and press enter, tab, space or comma",
maxTags: 10,
editable: true,
readOnly: false,
removeOnBackspace: true,
validator: undefined,
additionalKeycodes: [9, 32, 188] // tab, space, comma
};

function Example() {
Expand Down
6 changes: 4 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Tag} from "./components/Tag";
import {classSelectors} from "./utils/selectors";

type Tags = string[];
type Keycodes = number[];

export interface ReactTagInputProps {
tags: Tags;
Expand All @@ -13,6 +14,7 @@ export interface ReactTagInputProps {
editable?: boolean;
readOnly?: boolean;
removeOnBackspace?: boolean;
additionalKeycodes?: Keycodes;
}

interface State {
Expand All @@ -35,8 +37,8 @@ export default class ReactTagInput extends React.Component<ReactTagInputProps, S
const { input } = this.state;
const { validator, removeOnBackspace } = this.props;

// On enter
if (e.keyCode === 13) {
// On enter, or one of the additional keycodes from props
if (e.keyCode === 13 || this.props?.additionalKeycodes?.includes(e.keyCode)) {

// Prevent form submission if tag input is nested in <form>
e.preventDefault();
Expand Down