Skip to content

Commit

Permalink
error message and aria handling added
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Søberg committed Aug 28, 2017
1 parent a50e794 commit dd6e263
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 18 deletions.
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# Changelog for ffe-search-dropdown-react

## v.2.0.0
* Set inputValue outside the component to be able to reset and
change the value without interfering with the component.

## v2.1.0
* Added errorMessage prop
* Explicit aria-invalid handling in searchable-dropdown.less

## v2.0.0
* Set inputValue outside the component to be able to reset and
change the value without interfering with the component.
* attributes onSelect, onReset and onChange should now update inputValue and not return it.
* Removed attribute initialInputValue, added attribute inputValue.

## v1.1.4
* hotfix div wrapper classname with version for npm

## v.1.1.3
## v1.1.3
* Bumped version due to prepublish 1.1.2(unknown why)

## v1.1.2
Expand Down
14 changes: 11 additions & 3 deletions less/searchable-dropdown.less
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,25 @@
transition: all @ffe-transition-duration @ffe-ease;
width: 100%;

&:hover {
&[aria-invalid="true"] {
.ffe-chevron-icon-with-color(@ffe-orange-fire);
}

&:not([aria-invalid="true"]):hover {
border-color: @ffe-blue-azure;
}

&:focus,
&:active {
border-color: @ffe-blue-azure;
box-shadow: 0 0 0 2px @ffe-blue-focus;
outline: none;
}

&:not([aria-invalid="true"]):focus,
&:not([aria-invalid="true"]):active {
border-color: @ffe-blue-azure;
}

&:-moz-focusring {
color: transparent;
text-shadow: 0 0 0 @ffe-black;
Expand All @@ -53,7 +61,7 @@
}
}
&__display-reset {
background-image:none;
background-image:none!important;
}
&__reset-button {
position: absolute;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ffe-searchable-dropdown-react",
"version": "2.0.0",
"version": "2.1.0",
"description": "Dropdown with search option",
"scripts": {
"build": "babel -d lib --ignore=*.test.js src",
Expand Down
2 changes: 1 addition & 1 deletion src/InputField.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Input extends Component {
"ffe-searchable-dropdown__dropdown-input-field",
{"ffe-searchable-dropdown__display-reset": this.displayReset()}
)}
aria-invalid={ariaInvalid}
aria-invalid={ String(ariaInvalid) }
id={inputId}
onBlur={onBlur}
onChange={onInputChange}
Expand Down
17 changes: 10 additions & 7 deletions src/SearchableDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ class SearchableDropdown extends Component {
}

render() {
const { dropdownAttributes, noMatch, placeholder, renderDropdownElement, label } = this.props;
const { dropdownAttributes, noMatch, placeholder, renderDropdownElement, label, errorMessage } = this.props;
const { highlightedElementIndex, showListContainer, searchTerm } = this.state;
const filteredList = this.filterList(searchTerm);

return (
<div className={ classNames(this.props.className) }>
{label?
Expand All @@ -147,12 +148,7 @@ class SearchableDropdown extends Component {
</label>
: null
}
<div
className={classNames(
"ffe-searchable-dropdown",
this.props.className
)}
>
<div className="ffe-searchable-dropdown">
<Input
displayResetWhenInputHasValue = {this.props.displayResetWhenInputHasValue}
onBlur={this.onBlur}
Expand Down Expand Up @@ -181,6 +177,11 @@ class SearchableDropdown extends Component {
/>
}
</div>
{errorMessage &&
<div className="ffe-field-error-message">
{errorMessage}
</div>
}
</div>
);
}
Expand Down Expand Up @@ -221,6 +222,8 @@ SearchableDropdown.propTypes = {
ariaInvalid: bool,
/** css class for main div searchableDropdown */
className: string,
/** Error message */
errorMessage: string,
};

SearchableDropdown.defaultProps = {
Expand Down
8 changes: 6 additions & 2 deletions src/SearchableDropdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ describe('<SearchableDropdown>', () => {
inputValue:'',
displayResetWhenInputHasValue:true,
label:"Foo",
inputId: "inputid"
inputId: "inputid",
errorMessage: "404"
};

const setHighlightedIndexSpy = jest.spyOn(SearchableDropdown.prototype, 'setHighlightedIndex');
const component = mountDropdownWithProps(props);


test('errorMessage <div> ', () =>
expect(component.find('.ffe-field-error-message')).toHaveLength(1));

test('renders', () =>
expect(component.find('.ffe-searchable-dropdown')).toHaveLength(1));

Expand All @@ -49,6 +52,7 @@ describe('<SearchableDropdown>', () => {
expect(component.find(ScrollContainer)).toHaveLength(1);
expect(component.state('showListContainer')).toEqual(true);
});

test('renders <ScrollContainer> on arrowDown', () => {
const arrowDownEvent = {key: 'ArrowDown', preventDefault: i};
component.find(Input).prop('onKeyDown')(arrowDownEvent);
Expand Down

0 comments on commit dd6e263

Please sign in to comment.