Skip to content

Commit

Permalink
Add option to set the id attribute of the input field
Browse files Browse the repository at this point in the history
  • Loading branch information
Terje Røstum committed Jun 28, 2016
1 parent 42cae1a commit 5ba1f6d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ const accounts = [
onChange={ onChange }
onBlur={ onBlur }
locale="nb"
placeholder="Select account"
id="custom-id"
/>
```
- accounts: Array of account objects where only "name" is a required prop.
- onChange: callback who will receive a string value with either the users typed value or the account number for the account the user selected.
- onBlur: same as onChange, but called when the component looses focus.
- locale: Either "nb", "nn" or "en". Defaults to "nb" if not set.
- placeholder (optional): Set the placeholder attribute of the input field.
- id (optional): Set the id attribute of the input field so a label can be associated with the field.

You must also import the styles
```css
Expand Down
2 changes: 2 additions & 0 deletions examples/account-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ function onBlur() {

render(
<div>
<label htmlFor="custom-id" className="ffe-form-label">Velg konto</label>
<AccountSelector
accounts={ accounts }
onChange={ onChange }
onBlur={ onBlur }
locale="nb"
placeholder="Velg Konto"
id="custom-id"
/>
</div>
, accountSelectorDOM);
2 changes: 2 additions & 0 deletions src/account-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export default class AccountSelector extends React.Component {
onKeyDown={ this.onInputKeyDown }
ref={ assignTo('_accountInput') }
placeholder={this.props.placeholder}
id={ this.props.id }
aria-autocomplete="inline"
/>
{this.state.showResetButton ?
Expand Down Expand Up @@ -306,6 +307,7 @@ AccountSelector.propTypes = {
locale: PropTypes.string,
onBlur: PropTypes.func,
placeholder : PropTypes.string,
id : PropTypes.string,
};

AccountSelector.defaultValues = {
Expand Down

0 comments on commit 5ba1f6d

Please sign in to comment.