Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Window and focus question in order to quickly close a Window

    Hi Isomorphic,

    I often want to close windows very quickly. ESC would work perfect for that.
    But there seems to be some focus issue. The window itself can't have focus and won't have it after show()ing.
    Please see this sample (SNAPSHOT_v12.0d_2017-07-20).

    I can get what I want if I modify it like this:
    Code:
    isc.IButton.create({
        ID: "button",
        autoDraw: false,
        title: "Show Window",
        click : function () {
            modalWindow.show();
            [B]modalWindow.focus();[/B]
        }
    });
    
    isc.VLayout.create({
        defaultLayoutAlign: "center",
        members: [ button ]
    });
    
    isc.Window.create({
        ID: "modalWindow",
        title: "Modal Window",
        autoSize:true,
        autoCenter: true,
        isModal: true,
        showModalMask: true,
        autoDraw: false,
        [B]canFocus: true,[/B]
        items: [
            isc.DynamicForm.create({
                autoDraw: false,
                height: 48,
                padding:4,
                fields: [
                    {name: "field1", type: "select", valueMap: ["foo", "bar"]},
                    {name: "field2", type: "date"},
                    {type: "button", title: "Done",
                     click: "modalWindow.hide();" }
                ]
            })
        ]
    });
    Is there something I can do to have this behavior by default? IMHO it will be the expected behavior.
    I could set canFocus: true in Window.setDefaultProperties(), but I'd still need the modalWindow.focus().

    Is there some reason that you did not set canFocus: true?
    Is there some reason I should not set canFocus: true?

    Thank you & Best regards
    Blama

    #2
    You can just set dismissOnEscape, which should work when the window or any descendant has focus.

    Comment


      #3
      Hi Isomorphic,

      this does not work without canFocus:true. Just try the sample and remove that line and set dismissOnEscape:true.

      Without canFocus:true, the window does not have focus, so the ESC-Key won't work. Even clicking in the header area does not give the window focus then.

      Best regards
      Blama

      Comment


        #4
        Originally posted by Isomorphic View Post
        which should work when the window or any descendant has focus.
        IMHO the window can't have focus with your default settings for Window. Also it (or one descendant) won't have focus automatically after show().

        Comment


          #5
          Typically a dismissable dialog would have an "OK" button or similar, which should be given focus, since this then allows answering the dialog via hitting Enter. For a buttonless dialog, an alternative is to put focus on the close button. In both cases this is a more accessible UI than *only* allowing keyboard dismissal via Escape.

          Other than that, in general, if you want a widget that is not the focus of keyboard input to nevertheless react to keyboard input, you use global key handlers.

          Comment

          Working...
          X