calcite-design-system icon indicating copy to clipboard operation
calcite-design-system copied to clipboard

setFocus() requires a timeout in componentDidLoad()

Open AdelheidF opened this issue 2 years ago • 2 comments

Description

There is a change with setFocus in beta.94. The call itself works fine, but in the past I could just do this:

componentDidLoad(): void {
    this.panelNode.setFocus("back-button");
}

This no longer works. I have to add the setFocus() call into a timeout now. Not sure though what a reliable wait time is.

This is the case both for panel or flow-item, or if I want to set the focus on a close button I add myself. No difference there.

From @driskull

I think we can improve this in the future by setting up a promise internally and waiting for the component to load before resolving the promise and then setFocus would wait for that promise first. But I think we can wait for the component to load before focusing internally.

Acceptance Criteria

setFocus should not require a timeout in componentDidLoad()

Relevant Info

No response

Which Component

panel, flow-item, ...

Example Use Case

No response

Esri team

N/A

AdelheidF avatar Sep 21 '22 20:09 AdelheidF

Could be related to https://github.com/ionic-team/stencil/issues/3580.

jcfranco avatar Sep 21 '22 20:09 jcfranco

Yeah it might be related to that bug. Our solution would need to rely on componentDidLoad so if that's not working correctly then we can't really do anything.

driskull avatar Sep 22 '22 16:09 driskull

I did a little bit of testing, this seems to work fine if there are no async lifecycle methods in the child component.

@AdelheidF is this still an issue? If so, can you point me to where its occurring in code? I'd like to get some more info.

driskull avatar Nov 10 '22 22:11 driskull

Installed and assigned for verification.

github-actions[bot] avatar Nov 19 '22 00:11 github-actions[bot]

I can still repro with next.650. I have a few flow-items with footer buttons and in some cases it still requires a timeout of 200 for the footer button to get the focus on forward or backward flow movement. Same issue for header back button of flow-items. No async calls when opening the panels.

imageimage

AdelheidF avatar Dec 01 '22 20:12 AdelheidF

@AdelheidF Would it be possible to put a Codepen together for us to reproduce for a fix, and/or some context on where it might be occurring in the code? Want to make sure we're understanding the complexity fully to diagnose.

geospatialem avatar Dec 09 '22 21:12 geospatialem

@driskull has repro cases using our components. I have not managed to get it to happen in a simple codepen.

AdelheidF avatar Dec 09 '22 22:12 AdelheidF

Will be re-evaluating post 1.0 release to determine if this is in the scope of the components, and if so, prioritization for a future 2023 release.

geospatialem avatar Dec 12 '22 17:12 geospatialem

Using requestAnimationFrame() fixes it in many places. I'm wondering if this could be added to all calcite setFocus() calls.

AdelheidF avatar Dec 21 '22 23:12 AdelheidF

This also surfaced in a new addition to our doc site, where a setTimeout was needed to set the focus of a panel.

geospatialem avatar Jun 12 '23 21:06 geospatialem

Installed and assigned for verification.

github-actions[bot] avatar Jul 03 '23 23:07 github-actions[bot]

@AdelheidF Can you verify if the fix above mitigates componentDidLoad with setFocus in 1.5.0-next.16?

geospatialem avatar Jul 09 '23 23:07 geospatialem

Looks good with 1.5.0-next.36!

AdelheidF avatar Aug 03 '23 20:08 AdelheidF