Skip to content

Commit 056c3a1

Browse files
authored
Merge pull request ubilabs#246 from ubilabs/feat/blur
feat: add blur()
2 parents fcb4b0b + 41dab98 commit 056c3a1

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ These functions are accessible by setting "ref" on the component (see example be
254254
#### focus()
255255
Call `focus` to focus on the element. The suggest list will be expanded with the current suggestions.
256256

257+
#### blur()
258+
Call `blur` to blur (unfocus) the element. The suggest list will be closed.
259+
257260
#### update(value)
258261
It is possible to update the value of the input contained within the GeoSuggest component by calling the `update` function with a new desired `value` of the type String.
259262

src/Geosuggest.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ class Geosuggest extends React.Component {
143143
this.refs.input.focus();
144144
}
145145

146+
/**
147+
* Blur the input
148+
*/
149+
blur() {
150+
this.refs.input.blur();
151+
}
152+
146153
/**
147154
* Update the value of the user input
148155
* @param {String} userInput the new value of the user input

src/input.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ class Input extends React.Component {
9191
this.refs.input.focus();
9292
}
9393

94+
/**
95+
* Blur the input
96+
*/
97+
blur() {
98+
this.refs.input.blur();
99+
}
100+
94101
/**
95102
* Render the view
96103
* @return {Function} The React element to render

test/Geosuggest_spec.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ describe('Component: Geosuggest', () => {
244244
expect(document.activeElement.classList.contains('geosuggest__input')).to.be.true; // eslint-disable-line no-unused-expressions, max-len
245245
});
246246

247+
it('should not have the focus after calling `blur`', () => {
248+
component.focus();
249+
expect(document.activeElement.classList.contains('geosuggest__input')).to.be.true; // eslint-disable-line no-unused-expressions, max-len
250+
component.blur();
251+
expect(document.activeElement.classList.contains('geosuggest__input')).to.be.false; // eslint-disable-line no-unused-expressions, max-len
252+
});
253+
247254
it('should add external inline `style` to input component', () => { // eslint-disable-line max-len
248255
const geoSuggestInput = TestUtils.findRenderedDOMComponentWithClass(component, 'geosuggest__input'); // eslint-disable-line max-len
249256
expect(geoSuggestInput.style['border-color']).to.be.equal('#000');

0 commit comments

Comments
 (0)