-
Notifications
You must be signed in to change notification settings - Fork 75
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
Infinite loop when calling setFocus
on new calcite-input
#5882
Comments
Yeah, now this one isn't a doc cleanup issue 😬 Triaging to the current sprint, cc @driskull @geospatialem |
I think this might be because when the modal is opened it is trapping focus. We might need to provide an option to disable focus trap for modal here. |
@eriklharper can you take this one? It seems like an issue with I narrowed it down to a infinite loop in setFocus/input When The problem is when the input is focused, it calls |
It actually has nothing to do with the I'm guessing |
setFocus
on new calcite-input
inside a modalsetFocus
on new calcite-input
Could you share a codepen that reproduces this? I can't repro that with code like this (based on your description, assuming a button is wired up to fire this callback):
|
I was wrong, it does have to do with the focus trap but not modal specifically. It seems to fight the focus trap because of that infinite loop it gets into. here's a reproduction: |
If you change the JS to just use a native input it works fine. |
This is my finding as well after investigating. |
Installed and assigned for verification. |
Verified in |
* master: (55 commits) build: update browserslist db (#5986) docs: update component READMEs (#5980) 1.0.0-next.670 refactor(input-date-picker,date-picker)!: Removing deprecated locale properties (#5977) 1.0.0-next.669 refactor(input-date-picker)!: Remove deprecated active property (#5974) 1.0.0-next.668 fix(modal, popover): Add `disableFocusTrap` property to toggle focus trapping. (#5965) 1.0.0-next.667 refactor(input-time-picker)!: Remove deprecated active property (#5970) docs(changelog): fix breaking change indent levels (#5973) 1.0.0-next.666 refactor(time-picker)!: Remove deprecated locale property (#5962) 1.0.0-next.665 fix(input, input-number, input-text): Fix infinite loop crashing browser. #5882 (#5961) test(floating-ui): fix type errors (#5966) docs: update component READMEs (#5964) 1.0.0-next.664 fix(alert): auto-dismissible retains close button and dismisses timer while a user is hovering over (#5872) chore(color-picker): add opacity string (#5959) ...
@driskull, I'm having trouble with the solution because I'd like to continue trapping focus within the modal. Temporarily disabling the focus trap shifts focus back to the modal's close button when I re-enable the trap: https://codepen.io/nwhittaker-esri/pen/QWBwNxy. Would that be considered a bug? What is the recommend pattern for using the new FWIW, I was thinking you'd just call |
Yes, I tried this but it didn't seem to work. I think the focus-trap module has a bug with custom elements. I need to create a repro and open a bug for them. |
Hey Adelheid, for the focusing issue, have you tried using requestAnimationFrame instead of some timeout with a number? Like:
|
@nwhittaker created issue here: #6140 |
Actual Behavior
Programmatically inserting a
<calcite-input>
into a<calcite-modal>
and callingsetFocus()
on the input results in an infinite loop that locks up the window.Expected Behavior
Programmatically inserting a
<calcite-input>
into a<calcite-modal>
and callingsetFocus()
on it shifts focus to the input.Reproduction Sample
https://codepen.io/nwhittaker-esri/pen/VwdEody
Reproduction Steps
Reproduction Version
next.653
Relevant Info
The regression appears to have been introduced over a couple releases:
next.632
: refactor(modal): Update modal to use focus-trap module. #5676next.636
: fix: setFocus methods should wait for the component to be loaded #5749The likely root of the problem is the new focus trap library isn't aware of the new input element yet, so it thinks an element outside of the modal is being focused. The loop that emerges is:
setFocus()
called on the new<calcite-input>
.focus()
called on the shadow<input>
.focusin
handler reverts focus to the previously focused element.<calcite-input>
element'sfocus
handler runs and callssetFocus()
on itself which leads back to step 1.Regression?
next.631
Impact
The Field Maps web app uses a modal for editing coded value domains. When a user wants to add a new coded value, a new row of inputs is inserted and focus should shift to the row's first input. This is blocking us from upgrading Calcite beyond
next.631
.Esri team
ArcGIS Field Apps
The text was updated successfully, but these errors were encountered: