Skip to content
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

Fix minor regression #320

Merged
merged 5 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions dist/autofill-debug.js

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

25 changes: 14 additions & 11 deletions dist/autofill.js

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

22 changes: 22 additions & 0 deletions integration-test/tests/login-form.macos.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,28 @@ test.describe('Auto-fill a login form on macOS', () => {
await emailField.focus()
await login.assertFocusMessage()
})
test('when focusing a field below the fold', async ({page}) => {
// enable in-terminal exceptions
await forwardConsoleMessages(page)

await mocks(page)

// Load the autofill.js script with replacements
await createAutofillScript()
.replaceAll(macosContentScopeReplacements({overlay: true}))
.platform('macos')
.applyTo(page)

const login = loginPage(page, {overlay: true})

await login.navigate()
await page.waitForTimeout(200)

const offScreenField = await page.locator('#password-3')
await offScreenField.focus()

await login.assertFocusMessage()
})
})
test('by clicking a label', async ({page}) => {
await testLoginPage(page, {clickLabel: true, pageType: 'withExtraText'})
Expand Down
20 changes: 11 additions & 9 deletions src/UI/controllers/OverlayUIController.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,21 @@ export class OverlayUIController extends UIController {

const position = getPosition()

let delay = 0
// If the element is not in viewport, scroll there and recurse. 50ms is arbitrary
if (!click && !this.elementIsInViewport(position)) {
input.scrollIntoView(true)
delay = 500
this._mutObs?.disconnect()
setTimeout(() => {
this.attach(args)
}, 50)
return
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having the side-effect happen after a timeout, now we are calling this same function recursively after the timeout. This ensures that this.#state is consistent across calls. The 500 delay was likely arbitrary and 50 works just as well, so shorter is better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GioSensation NAB: Do we want to provide a comment for context on the 50 value to help future us? (i.e. it's just some value to throttle repeated calls)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment above to explain why we're recursing, plus that the 50 is arbitrary.

}
this.#state = 'parentShown'
setTimeout(() => {
this.showTopTooltip(click, position, topContextData)
.catch(e => {
console.error('error from showTopTooltip', e)
this.#state = 'idle'
})
}, delay)
this.showTopTooltip(click, position, topContextData)
.catch(e => {
console.error('error from showTopTooltip', e)
this.#state = 'idle'
})
}

/**
Expand Down
25 changes: 14 additions & 11 deletions swift-package/Resources/assets/autofill-debug.js

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

25 changes: 14 additions & 11 deletions swift-package/Resources/assets/autofill.js

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