Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Commit

Permalink
Input prop audit
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Scott committed Feb 2, 2017
1 parent 1999ed9 commit 632116a
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 317 deletions.
6 changes: 6 additions & 0 deletions packages/boundless-input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ There are no required props.

### Optional Props

- __`component`__ ・ overrides the HTML container tag

Expects | Default Value
- | -
`string` | `'div'`

- __`hidePlaceholderOnFocus`__ ・ triggers the placeholder to disappear when the input field is focused, reappears when the user has tabbed away or focus is moved

Expects | Default Value
Expand Down
29 changes: 16 additions & 13 deletions packages/boundless-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ When using `Input` in your project, you may call the following methods on a rend
*/
export default class Input extends React.PureComponent {
static propTypes = {
/**
* overrides the HTML container tag
*/
component: PropTypes.string,

/**
* triggers the placeholder to disappear when the input field is focused, reappears when the user has tabbed away or focus is moved
*/
Expand All @@ -43,6 +48,7 @@ export default class Input extends React.PureComponent {
}

static defaultProps = {
component: 'div',
hidePlaceholderOnFocus: true,
inputProps: {
type: 'text',
Expand Down Expand Up @@ -118,35 +124,32 @@ export default class Input extends React.PureComponent {

getPlaceholderText() {
const isNonEmpty = this.state.input !== '';
const shouldShowPlaceholder = this.props.hidePlaceholderOnFocus === true
? this.state.isFocused === false && isNonEmpty === false
: isNonEmpty === false;
const shouldShowPlaceholder = this.props.hidePlaceholderOnFocus === true
? this.state.isFocused === false && isNonEmpty === false
: isNonEmpty === false;

return shouldShowPlaceholder ? this.props.inputProps.placeholder : '';
}

render() {
const {props} = this;

return (
<div
{...omit(props, Input.internalKeys)}
ref='wrapper'
className={cx('b-input-wrapper', props.className)}
<this.props.component
{...omit(this.props, Input.internalKeys)}
className={cx('b-input-wrapper', this.props.className)}
title={this.getPlaceholderText()}>
<input
{...props.inputProps}
{...this.props.inputProps}
ref='field'
className={cx('b-input', props.inputProps.className)}
className={cx('b-input', this.props.inputProps.className)}
placeholder={null}
onBlur={this.handleBlur}
onFocus={this.handleFocus}
onChange={this.handleChange} />

<div ref='placeholder' className='b-input-placeholder b-input'>
<div className='b-input-placeholder b-input'>
{this.getPlaceholderText()}
</div>
</div>
</this.props.component>
);
}
}
Loading

0 comments on commit 632116a

Please sign in to comment.