Skip to content

Commit

Permalink
fix(ld-select): remove unnecessary settimeout for autofocus
Browse files Browse the repository at this point in the history
  • Loading branch information
borisdiakur committed Nov 30, 2021
1 parent ebb43ff commit 9fcd2c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
7 changes: 3 additions & 4 deletions src/liquid/components/ld-select/ld-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -884,11 +884,10 @@ export class LdSelect implements InnerFocusable {
setTimeout(() => {
this.initObserver()
this.initialized = true

if (this.autofocus) {
this.focusInner()
}
})
if (this.autofocus) {
this.focusInner()
}
}

componentDidUpdate() {
Expand Down
22 changes: 0 additions & 22 deletions src/liquid/components/ld-select/test/ld-select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2008,26 +2008,4 @@ describe('ld-select', () => {
await page.root.focusInner()
expect((btnTrigger as HTMLElement).focus).toHaveBeenCalledTimes(1)
})

it('auto-focuses', async () => {
const page = await newSpecPage({
components,
html: `
<ld-select autofocus placeholder="Pick a fruit" name="fruit" popper-class="ld-select__popper--fruits">
<ld-option value="apple">Apple</ld-option>
<ld-option value="banana">Banana</ld-option>
</ld-select>
`,
})

const ldSelect = page.root
const btnTrigger = ldSelect.shadowRoot.querySelector(
'.ld-select__btn-trigger'
)
;(btnTrigger as HTMLElement).focus = jest.fn()

await page.waitForChanges()
jest.advanceTimersByTime(0)
expect((btnTrigger as HTMLElement).focus).toHaveBeenCalledTimes(1)
})
})

0 comments on commit 9fcd2c6

Please sign in to comment.