Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Dropdown): allow autoComplete on DropdownSearchInput #2738

Merged
merged 1 commit into from
Apr 27, 2018
Merged
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: 3 additions & 0 deletions src/modules/Dropdown/DropdownSearchInput.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export interface DropdownSearchInputProps {
/** An element type to render as (string or function). */
as?: any;

/** An input can have the auto complete. */
autoComplete?: string;

/** Additional classes. */
className?: string;

Expand Down
25 changes: 9 additions & 16 deletions src/modules/Dropdown/DropdownSearchInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import _ from 'lodash'
import PropTypes from 'prop-types'
import React, { Component } from 'react'

import {
createShorthandFactory,
customPropTypes,
META,
getUnhandledProps,
} from '../../lib'
import { createShorthandFactory, customPropTypes, META, getUnhandledProps } from '../../lib'

/**
* A search item sub-component for Dropdown component.
Expand All @@ -18,29 +13,27 @@ class DropdownSearchInput extends Component {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** An input can have the auto complete. */
autoComplete: PropTypes.string,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I remember, there can be on and off values.

https://www.w3schools.com/tags/att_input_autocomplete.asp


/** Additional classes. */
className: PropTypes.string,

/** A ref handler for input. */
inputRef: PropTypes.func,

/** An input can receive focus. */
tabIndex: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
]),
tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),

/** The HTML input type. */
type: PropTypes.string,

/** Stored value. */
value: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
]),
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
}

static defaultProps = {
autoComplete: 'off',
type: 'text',
}

Expand All @@ -59,15 +52,15 @@ class DropdownSearchInput extends Component {
handleRef = c => _.invoke(this.props, 'inputRef', c)

render() {
const { className, tabIndex, type, value } = this.props
const { autoComplete, className, tabIndex, type, value } = this.props
const classes = cx('search', className)
const rest = getUnhandledProps(DropdownSearchInput, this.props)

return (
<input
{...rest}
aria-autocomplete='list'
autoComplete='off'
autoComplete={autoComplete}
className={classes}
onChange={this.handleChange}
ref={this.handleRef}
Expand Down
30 changes: 13 additions & 17 deletions test/specs/modules/Dropdown/DropdownSearchInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ describe('DropdownSearchInput', () => {

describe('aria', () => {
it('should have aria-autocomplete', () => {
shallow(<DropdownSearchInput />)
.should.have.prop('aria-autocomplete', 'list')
shallow(<DropdownSearchInput />).should.have.prop('aria-autocomplete', 'list')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier has done some work there 😃

})
})

describe('autoComplete', () => {
it('should have autoComplete', () => {
shallow(<DropdownSearchInput />)
.should.have.prop('autoComplete', 'off')
it('should have autoComplete by default', () => {
shallow(<DropdownSearchInput />).should.have.prop('autoComplete', 'off')
})

it('should pass a defined value', () => {
shallow(<DropdownSearchInput autoComplete='on' />).should.have.prop('autoComplete', 'on')
})
})

Expand Down Expand Up @@ -55,41 +57,35 @@ describe('DropdownSearchInput', () => {

describe('tabIndex', () => {
it('is not set by default', () => {
shallow(<DropdownSearchInput />)
.should.not.have.prop('tabIndex')
shallow(<DropdownSearchInput />).should.not.have.prop('tabIndex')
})

it('can be set explicitly', () => {
shallow(<DropdownSearchInput tabIndex={123} />)
.should.have.prop('tabIndex', 123)
shallow(<DropdownSearchInput tabIndex={123} />).should.have.prop('tabIndex', 123)
})
})

describe('type', () => {
it('should have text by default', () => {
shallow(<DropdownSearchInput />)
.should.have.prop('type', 'text')
shallow(<DropdownSearchInput />).should.have.prop('type', 'text')
})

it('can be set explicitly', () => {
const type = faker.random.word()

shallow(<DropdownSearchInput type={type} />)
.should.have.prop('type', type)
shallow(<DropdownSearchInput type={type} />).should.have.prop('type', type)
})
})

describe('value', () => {
it('is not set by default', () => {
shallow(<DropdownSearchInput />)
.should.not.have.prop('value')
shallow(<DropdownSearchInput />).should.not.have.prop('value')
})

it('can be set explicitly', () => {
const value = faker.random.word()

shallow(<DropdownSearchInput value={value} />)
.should.have.prop('value', value)
shallow(<DropdownSearchInput value={value} />).should.have.prop('value', value)
})
})
})