-
Notifications
You must be signed in to change notification settings - Fork 65
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(component): add filterable prop to Select #227
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import { ListCheckboxItem } from '../List/Item/CheckboxItem'; | |
import { ListItem } from '../List/Item/Item'; | ||
import { List } from '../List/List'; | ||
|
||
import { StyledDropdownIcon, StyledStatusMessage } from './styled'; | ||
import { StyledDropdownIcon, StyledInputContainer, StyledStatusMessage } from './styled'; | ||
import { Action, Option, SelectProps } from './types'; | ||
|
||
interface SelectState { | ||
|
@@ -63,7 +63,18 @@ export class Select<T extends any> extends React.PureComponent<SelectProps<T>, S | |
} | ||
|
||
render() { | ||
const { children, label, maxHeight, multi, onChange, placeholder, placement, value, ...rest } = this.props; | ||
const { | ||
children, | ||
filterable, | ||
label, | ||
maxHeight, | ||
multi, | ||
onChange, | ||
placeholder, | ||
placement, | ||
value, | ||
...rest | ||
} = this.props; | ||
|
||
const { isOpen } = this.state; | ||
|
||
|
@@ -120,7 +131,7 @@ export class Select<T extends any> extends React.PureComponent<SelectProps<T>, S | |
} | ||
|
||
private renderInput() { | ||
const { placeholder, error, required, disabled, onChange, options, value } = this.props; | ||
const { placeholder, error, filterable = true, required, disabled, onChange, options, value } = this.props; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the best way to set a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be fine. In this case since the prop is at the class level, it might be better to add it onto |
||
const { highlightedItem, inputText, isOpen } = this.state; | ||
const ariaActiveDescendant = highlightedItem ? { 'aria-activedescendant': highlightedItem.id } : {}; | ||
const ariaControls = isOpen ? { 'aria-controls': this.getSelectId() } : {}; | ||
|
@@ -143,7 +154,7 @@ export class Select<T extends any> extends React.PureComponent<SelectProps<T>, S | |
return ( | ||
<Reference> | ||
{({ ref }) => ( | ||
<span ref={ref}> | ||
<StyledInputContainer ref={ref}> | ||
<Input | ||
aria-autocomplete="list" | ||
autoComplete="off" | ||
|
@@ -154,17 +165,19 @@ export class Select<T extends any> extends React.PureComponent<SelectProps<T>, S | |
id={this.getInputId()} | ||
onChange={this.handleOnInputChange} | ||
onChipDelete={chips && onChipDelete} | ||
onFocus={this.handleOnInputFocus} | ||
onClick={this.handleOnInputSelected} | ||
onFocus={this.handleOnInputSelected} | ||
onKeyDown={this.handleOnInputKeyDown} | ||
placeholder={placeholder} | ||
readOnly={!filterable} | ||
ref={this.inputRef} | ||
required={required} | ||
type={'text'} | ||
value={inputText} | ||
{...ariaActiveDescendant} | ||
{...ariaControls} | ||
></Input> | ||
</span> | ||
/> | ||
</StyledInputContainer> | ||
)} | ||
</Reference> | ||
); | ||
|
@@ -496,7 +509,7 @@ export class Select<T extends any> extends React.PureComponent<SelectProps<T>, S | |
return this.updateHighlightedItem(event.currentTarget); | ||
}; | ||
|
||
private handleOnInputFocus = () => { | ||
private handleOnInputSelected = () => { | ||
if (!this.state.isOpen) { | ||
this.toggleList(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed, so I added it back.