问题
I am trying to set initial focus to the first input field in each page of my app.
I have implemented the code in the following post and it is working great:
How to Set Initial Focus in a View?
But I found that it is not working for first view/page in app when it opens from Fiori Launchpad. I found the following code which is getting executed after my onAfterShow
:
From sap/ushell/renderers/fiori2/Shell-dbg.controller.js
Could you please help to solve this? I am using SAP UI5 version 1.56.7.
回答1:
Solved the issue by passing around 200ms into setTimeout function for first page and it is working fine
回答2:
Author of that answer here. After browsing through the source code and documentation quite a while, I have to admit I couldn't find any acceptable solutions to this question either. My impression is that FLP developers want to make sure that the app doesn't interfere with setting the initial focus.
The lack of APIs and documentation thereof strongly suggests that there are compelling reasons behind this prevention (probably a11y related).
My advice is not to rely on timeouts but maintaining consistent UX by keeping the focus on the app title on its launch - as designed by SAP.
来源:https://stackoverflow.com/questions/55510704/flp-setting-custom-initial-focus-on-app-launch-fails