Sha256: 4fd0e8633ecb361f711d071104aa59705a498923109f6a5c6aaad66a33964a62

Contents?: true

Size: 860 Bytes

Versions: 15

Compression:

Stored size: 860 Bytes

Contents

import React, { useState } from "react";
import PropTypes from "prop-types";

export default function AddTagForm(props) {
  const [tag, setTag] = useState("");

  const submit = (evt) => {
    evt.preventDefault();
    props.addTag(tag);
    setTag("");
  };

  const handleKeyDown = (evt) => {
    if (evt.which === 13) {
      submit(evt);
    }
  };

  const handleChange = (evt) => {
    setTag(evt.target.value);
  };

  return (
    <div className="add-tag-form">
      <input name="add-tag"
             type="text"
             className="add-tag"
             value={tag}
             onKeyDown={handleKeyDown}
             onChange={handleChange}
             placeholder="Add tag..." />
      <button onClick={submit}
              disabled={!tag}>
        Add
      </button>
    </div>
  );
}

AddTagForm.propTypes = {
  addTag: PropTypes.func
};

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pages_core-3.12.1 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.12.0 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.11.3 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.11.2 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.11.1 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.11.0 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.10.2 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.10.1 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.9.2 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.9.1 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.9.0 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.8.3 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.8.2 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.8.1 app/javascript/components/TagEditor/AddTagForm.jsx
pages_core-3.8.0 app/javascript/components/TagEditor/AddTagForm.jsx