Focus handling in ResponsivePopover / Dialog / Popover

╄→尐↘猪︶ㄣ 提交于 2019-12-24 07:59:45

问题


I struggle to understand the automatic focus handling in SAPUI5 and how to change its default behavior:

Let's say I have a ResponsivePopover with a SearchField in it. When I open the popover, the SearchField gets focused automatically.

However when there is an <endButton> aggregation with a Button in it, it gets the focus instead.

Try it out here: JSbin: Focus in ResponsivePopover

function showPopover(oEvent) {
  var oRespPopover = new ResponsivePopover({
    showHeader: true,
    title: "title",
    content: [
      new SearchField(),
      // ...
    ],
    /*
    endButton: new sap.m.Button({
      text: 'close',
      press: function(oEvent) {
        oRespPopover.close();
      }
    }),
    */
    afterClose: function(oEvent) {
      oEvent.getSource().destroy();
    }
  });
  oRespPopover.openBy(oBtn);
};

General question

Where is defined which Control gets the focus and how can I change this behavior? I checked the Implementing Focus Handling documentation on this topic, but did not manage to achieve anything.

My specific case

How can I prevent that the SearchField gets the focus (because that triggers the keyboard on mobile devices), without having an EndButton aggregation?


回答1:


If the target control has a stable ID, you can assign that ID to the initialFocus association of the ResponsivePopover, Dialog, or Popover so that the target control gets focused even if there are buttons in the end/beginButton aggregation.

Focus on the popover is set in the sequence of beginButton and endButton, when available. But if a control other than these two buttons needs to get the focus, set the initialFocus with the control which should be focused on. src

In XML:

initialFocus="myId">
<content>
  <SomeControl id="myId" />
</content>

Or in JS (Controller):

// ...
title: "title",
initialFocus: this.getView().createId("myId"),
content: [
  new SomeControl({
    id: this.getView().createId("myId"),
  }),
// ...

Note: For mobile devices, initial focus does not trigger opening the on-screen keyboard.

Setting initialFocus to input controls doesn't open the On-Screen keyboard on mobile device as, due to browser limitation, the On-Screen keyboard can't be opened with JavaScript code. The opening of On-Screen keyboard must be triggered by real user action. src



来源:https://stackoverflow.com/questions/46547481/focus-handling-in-responsivepopover-dialog-popover

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!