Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
Merge 324aa59 into 03886c7
Browse files Browse the repository at this point in the history
  • Loading branch information
tjbo committed Oct 12, 2019
2 parents 03886c7 + 324aa59 commit ebc64fc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@helpscout/hsds-react",
"version": "2.68.2",
"version": "2.68.3",
"private": false,
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down
5 changes: 4 additions & 1 deletion src/components/Input/Input.tsx
Expand Up @@ -114,6 +114,8 @@ export class Input extends React.PureComponent<InputProps, InputState> {
}
}

autoFocusTimeoutId = setTimeout(() => '', 0)

componentDidMount() {
this.maybeForceAutoFocus()
this.props.withTypingEvent &&
Expand Down Expand Up @@ -143,6 +145,7 @@ export class Input extends React.PureComponent<InputProps, InputState> {
componentWillUnmount() {
this.inputNode = null
this.props.withTypingEvent && this.clearTypingTimeout()
this.autoFocusTimeoutId && clearTimeout(this.autoFocusTimeoutId)
}

setValue = value => {
Expand Down Expand Up @@ -179,7 +182,7 @@ export class Input extends React.PureComponent<InputProps, InputState> {
forceAutoFocus() {
const { forceAutoFocusTimeout } = this.props

setTimeout(() => {
this.autoFocusTimeoutId = setTimeout(() => {
/* istanbul ignore else */
if (this.inputNode) {
this.inputNode.focus()
Expand Down
1 change: 1 addition & 0 deletions src/components/Input/Input.types.ts
Expand Up @@ -26,6 +26,7 @@ export type InputValue = string
export type InputProps = {
action?: any
autoFocus: boolean
autoFocusTimeoutId: any
charValidatorLimit: number
className: string
disabled: boolean
Expand Down
14 changes: 12 additions & 2 deletions src/components/Input/__tests__/Input.test.js
Expand Up @@ -716,7 +716,7 @@ describe('Typing events', () => {
expect(spies.callStartTyping).toHaveBeenCalledTimes(1)
expect(spies.setTypingTimeout).toHaveBeenCalledTimes(1)
expect(spies.onStartTyping).toHaveBeenCalledTimes(1)
expect(setTimeout).toHaveBeenCalledTimes(1)
expect(setTimeout.mock.calls[1][1]).toEqual(3000)
})

test('After a delay of 3000ms and no more typing events, should call stop typing events and clear timeout', () => {
Expand Down Expand Up @@ -766,7 +766,6 @@ describe('Typing events', () => {
wrapper.find('input').simulate('change')
wrapper.unmount()
expect(spies.clearTypingTimeout).toHaveBeenCalledTimes(2)
expect(clearTimeout).toHaveBeenCalledTimes(1)
})

test('Should call callStopTyping on refApplyCallStopTyping', () => {
Expand All @@ -779,6 +778,17 @@ describe('Typing events', () => {
})
})

describe('Unmount', () => {
it('should call clearTimeout once when the component unmounts', () => {
const clearTimeout = jest.spyOn(window, 'clearTimeout')
const wrapper = mount(<Input />)
wrapper.find('input').simulate('change')
const id = wrapper.instance().autoFocusTimeoutId
wrapper.unmount()
expect(clearTimeout).toHaveBeenCalledWith(id)
})
})

describe('ErrorMessage', () => {
test('Does not render an error Icon if suffix is defined', () => {
const wrapper = mount(<Input suffix="Derek" />)
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/pkg.ts
@@ -1,3 +1,3 @@
export default {
version: '2.68.2',
version: '2.68.3',
}

0 comments on commit ebc64fc

Please sign in to comment.