Input Group

Input Group - 图1

  1. import React from 'react';
  2. import { InputGroup, InputGroupAddon, InputGroupText, Input } from 'reactstrap';
  3. const Example = (props) => {
  4. return (
  5. <div>
  6. <InputGroup>
  7. <InputGroupAddon addonType="prepend">@</InputGroupAddon>
  8. <Input placeholder="username" />
  9. </InputGroup>
  10. <br />
  11. <InputGroup>
  12. <InputGroupAddon addonType="prepend">
  13. <InputGroupText>
  14. <Input addon type="checkbox" aria-label="Checkbox for following text input" />
  15. </InputGroupText>
  16. </InputGroupAddon>
  17. <Input placeholder="Check it out" />
  18. </InputGroup>
  19. <br />
  20. <InputGroup>
  21. <Input placeholder="username" />
  22. <InputGroupAddon addonType="append">
  23. <InputGroupText>@example.com</InputGroupText>
  24. </InputGroupAddon>
  25. </InputGroup>
  26. <br />
  27. <InputGroup>
  28. <InputGroupAddon addonType="prepend">
  29. <InputGroupText>$</InputGroupText>
  30. <InputGroupText>$</InputGroupText>
  31. </InputGroupAddon>
  32. <Input placeholder="Dolla dolla billz yo!" />
  33. <InputGroupAddon addonType="append">
  34. <InputGroupText>$</InputGroupText>
  35. <InputGroupText>$</InputGroupText>
  36. </InputGroupAddon>
  37. </InputGroup>
  38. <br />
  39. <InputGroup>
  40. <InputGroupAddon addonType="prepend">$</InputGroupAddon>
  41. <Input placeholder="Amount" min={0} max={100} type="number" step="1" />
  42. <InputGroupAddon addonType="append">.00</InputGroupAddon>
  43. </InputGroup>
  44. </div>
  45. );
  46. };
  47. export default Example;

Properties

  1. InputGroup.propTypes = {
  2. tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
  3. size: PropTypes.string,
  4. className: PropTypes.string
  5. };
  6. InputGroupAddOn.propTypes = {
  7. tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
  8. addonType: PropTypes.oneOf(['prepend', 'append']).isRequired,
  9. className: PropTypes.string
  10. };
  11. InputGroupButton.propTypes = {
  12. tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
  13. addonType: PropTypes.oneOf(['prepend', 'append']).isRequired,
  14. children: PropTypes.node,
  15. groupClassName: PropTypes.string, // only used in shorthand
  16. groupAttributes: PropTypes.object, // only used in shorthand
  17. className: PropTypes.string
  18. };

Addons

Input Group - 图2

  1. import React from 'react';
  2. import { InputGroup, InputGroupText, InputGroupAddon, Input } from 'reactstrap';
  3. const Example = (props) => {
  4. return (
  5. <div>
  6. <InputGroup>
  7. <InputGroupAddon addonType="prepend">
  8. <InputGroupText>To the Left!</InputGroupText>
  9. </InputGroupAddon>
  10. <Input />
  11. </InputGroup>
  12. <br />
  13. <InputGroup>
  14. <Input />
  15. <InputGroupAddon addonType="append">
  16. <InputGroupText>To the Right!</InputGroupText>
  17. </InputGroupAddon>
  18. </InputGroup>
  19. <br />
  20. <InputGroup>
  21. <InputGroupAddon addonType="prepend">
  22. <InputGroupText>To the Left!</InputGroupText>
  23. </InputGroupAddon>
  24. <Input placeholder="and..." />
  25. <InputGroupAddon addonType="append">
  26. <InputGroupText>To the Right!</InputGroupText>
  27. </InputGroupAddon>
  28. </InputGroup>
  29. </div>
  30. );
  31. };
  32. export default Example;

Addon Sizing

Input Group - 图3

  1. import React from 'react';
  2. import { InputGroup, InputGroupAddon, Input } from 'reactstrap';
  3. const Example = (props) => {
  4. return (
  5. <div>
  6. <InputGroup size="lg">
  7. <InputGroupAddon addonType="prepend">@lg</InputGroupAddon>
  8. <Input />
  9. </InputGroup>
  10. <br />
  11. <InputGroup>
  12. <InputGroupAddon addonType="prepend">@normal</InputGroupAddon>
  13. <Input />
  14. </InputGroup>
  15. <br />
  16. <InputGroup size="sm">
  17. <InputGroupAddon addonType="prepend">@sm</InputGroupAddon>
  18. <Input />
  19. </InputGroup>
  20. </div>
  21. );
  22. };
  23. export default Example;

Buttons / Dropdowns

Input Group - 图4

  1. import React from 'react';
  2. import {
  3. InputGroup,
  4. InputGroupAddon,
  5. InputGroupButtonDropdown,
  6. InputGroupDropdown,
  7. Input,
  8. Button,
  9. Dropdown,
  10. DropdownToggle,
  11. DropdownMenu,
  12. DropdownItem
  13. } from 'reactstrap';
  14. export default class Example extends React.Component {
  15. constructor(props) {
  16. super(props);
  17. this.toggleDropDown = this.toggleDropDown.bind(this);
  18. this.toggleSplit = this.toggleSplit.bind(this);
  19. this.state = {
  20. dropdownOpen: false,
  21. splitButtonOpen: false
  22. };
  23. }
  24. toggleDropDown() {
  25. this.setState({
  26. dropdownOpen: !this.state.dropdownOpen
  27. });
  28. }
  29. toggleSplit() {
  30. this.setState({
  31. splitButtonOpen: !this.state.splitButtonOpen
  32. });
  33. }
  34. render() {
  35. return (
  36. <div>
  37. <InputGroup>
  38. <InputGroupAddon addonType="prepend"><Button>I'm a button</Button></InputGroupAddon>
  39. <Input />
  40. </InputGroup>
  41. <br />
  42. <InputGroup>
  43. <Input />
  44. <InputGroupButtonDropdown addonType="append" isOpen={this.state.dropdownOpen} toggle={this.toggleDropDown}>
  45. <DropdownToggle caret>
  46. Button Dropdown
  47. </DropdownToggle>
  48. <DropdownMenu>
  49. <DropdownItem header>Header</DropdownItem>
  50. <DropdownItem disabled>Action</DropdownItem>
  51. <DropdownItem>Another Action</DropdownItem>
  52. <DropdownItem divider />
  53. <DropdownItem>Another Action</DropdownItem>
  54. </DropdownMenu>
  55. </InputGroupButtonDropdown>
  56. </InputGroup>
  57. <br />
  58. <InputGroup>
  59. <InputGroupButtonDropdown addonType="prepend" isOpen={this.state.splitButtonOpen} toggle={this.toggleSplit}>
  60. <Button outline>Split Button</Button>
  61. <DropdownToggle split outline />
  62. <DropdownMenu>
  63. <DropdownItem header>Header</DropdownItem>
  64. <DropdownItem disabled>Action</DropdownItem>
  65. <DropdownItem>Another Action</DropdownItem>
  66. <DropdownItem divider />
  67. <DropdownItem>Another Action</DropdownItem>
  68. </DropdownMenu>
  69. </InputGroupButtonDropdown>
  70. <Input placeholder="and..." />
  71. <InputGroupAddon addonType="append"><Button color="secondary">I'm a button</Button></InputGroupAddon>
  72. </InputGroup>
  73. </div>
  74. );
  75. }
  76. }

Button Shorthand (DEPRECATED)

Button shorthand is deprecated. Below are the updated examples of how to use InputGroupAddon to accomplish the same output.

Button shorthand is a convenience method for adding just a button. It is triggered when only a single string is the child. A Button will be created and all of the props will be passed to it with the exception ofgroupClassName and groupAttributes, which are used to added classes and attributes to the wrapping container. This means you can add your onClick and other handlers directly toInputGroupButton. If you want your string to not be wrapped in a button, then you really want to use InputGroupAddon (see Addons above for that).

Input Group - 图5

  1. import React from 'react';
  2. import { InputGroup, InputGroupAddon, Button, Input } from 'reactstrap';
  3. const Example = (props) => {
  4. return (
  5. <div>
  6. <InputGroup>
  7. <InputGroupAddon addonType="prepend">
  8. <Button>To the Left!</Button>
  9. </InputGroupAddon>
  10. <Input />
  11. </InputGroup>
  12. <br />
  13. <InputGroup>
  14. <Input />
  15. <InputGroupAddon addonType="append">
  16. <Button color="secondary">To the Right!</Button>
  17. </InputGroupAddon>
  18. </InputGroup>
  19. <br />
  20. <InputGroup>
  21. <InputGroupAddon addonType="prepend">
  22. <Button color="danger">To the Left!</Button>
  23. </InputGroupAddon>
  24. <Input placeholder="and..." />
  25. <InputGroupAddon addonType="append">
  26. <Button color="success">To the Right!</Button>
  27. </InputGroupAddon>
  28. </InputGroup>
  29. </div>
  30. );
  31. };
  32. export default Example;