All files / packages/design-system/ui/components/input index.jsx

100% Statements 5/5
100% Branches 4/4
100% Functions 0/0
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90                                          268x   255x           255x                                   18x       18x                                                                            
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
 
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
 
const Input = props => {
  const {
    id,
    className,
    type,
    placeholder,
    readOnly,
    defaultValue,
    disabled,
    required,
    role,
    tabIndex,
    isBare,
    hasBorders
  } = props;
 
  const computedClassNames = {
    'slds-input_bare': isBare,
    'slds-input_counter': type === 'number',
    'slds-input_borders': readOnly && hasBorders
  };
 
  return (
    <input
      {...props}
      id={id}
      className={classNames('slds-input', computedClassNames, className)}
      type={type}
      placeholder={placeholder}
      readOnly={readOnly}
      defaultValue={defaultValue}
      disabled={disabled}
      required={required}
      aria-invalid={props['aria-describedby'] ? 'true' : undefined}
      role={role}
      tabIndex={tabIndex}
    />
  );
};
 
Input.defaultProps = {
  type: 'text'
};
 
Input.propTypes = {
  id: PropTypes.string,
  className: PropTypes.string,
  type: PropTypes.oneOf([
    'checkbox',
    'color',
    'date',
    'datetime-local',
    'email',
    'file',
    'hidden',
    'image',
    'month',
    'number',
    'password',
    'radio',
    'range',
    'reset',
    'search',
    'submit',
    'tel',
    'text',
    'time',
    'url',
    'week'
  ]),
  placeholder: PropTypes.string,
  readOnly: PropTypes.bool,
  defaultValue: PropTypes.string,
  disabled: PropTypes.bool,
  required: PropTypes.bool,
  role: PropTypes.string,
  tabIndex: PropTypes.string,
  isBare: PropTypes.bool,
  hasBorders: PropTypes.bool
};
 
export default Input;