Announcement

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

    Closing a dialog with ESC

    Hello again
    I have created an "about" dialog (with some text information and a "Close" button at to bottom)
    I would like to be able to close this dialog using just the ESC key.
    If I set the focus in the "Close" button, then pressing the ESC key the dialog closes, but if the focus in in the Dialog itself (not in some controll - the only control is the "Close" button) the ESC does not closes the Dialog.

    Cheers.

    Yorgos

    #2
    Not every element is focusable, so you may not have actually succeeded in putting focus on the dialog. Dismissing via escape is only intended to work if focus is within the dialog.

    Comment


      #3
      The following code creates a dialog
      After I show() it, I can't close it using ESC.
      If I set the focus in the btnClose, then the ESC closes the dialog.


      import com.smartgwt.client.widgets.Button;
      import com.smartgwt.client.widgets.Dialog;
      import com.smartgwt.client.widgets.HTMLFlow;
      import com.smartgwt.client.widgets.events.ClickEvent;
      import com.smartgwt.client.widgets.events.ClickHandler;

      public class DlgAbout extends Dialog
      {
      public DlgAbout ()
      {
      setTitle ("Σχετικά με το πρόγραμμα.");
      setIsModal (true);
      setAutoSize (true);
      setShowStatusBar (false);
      setShowFooter (false);
      setShowResizer (false);
      setShowResizeBar (false);
      setShowShadow (true);

      String s = "To <b>Amesias</b> είναι ένας δυκτιακός τόπος...<br>";
      s += "Μπορείτε ακόμα να ...<br>";

      final HTMLFlow htmlFlow = new HTMLFlow();
      htmlFlow.setTop(40);
      htmlFlow.setWidth(350);
      htmlFlow.setStyleName("aboutTextBlock");
      htmlFlow.setContents (s);

      this.addItem (htmlFlow);

      Button btnClose = new Button ("Close");
      btnClose.addClickHandler (new ClickHandler()
      {
      public void onClick (ClickEvent event)
      {
      hide ();
      }
      });

      setToolbarButtons (btnClose);
      }
      }

      Comment


        #4
        This is the intended behavior - focus must be within the dialog for it to close when escape is pressed.

        Comment


          #5
          Still it doesn't seems to me as intended.
          I display the dialog with .show(), I press on the caption (with the mouse) and move it here and there, I expect it to close when I press ESC.
          But it does not.
          I need to set the focus on "Close" button (or some other control) in order for the ESC to close the dialog.

          Comment


            #6
            Just tried this with the dialog launched by isc.say() and, even after dragging, escape works to dismiss the window. Are you seeing something different?

            Comment


              #7
              SC.say () closes with ESC in my program too (I just tried it).
              But not the code that I describe (I need to set the focus in the control intentionally in order for the ESC to work).

              Comment


                #8
                OK so, again: it is intended that you should have to set the focus in the control in order for dismissOnEscape to work. So just to be absolutely crystal clear, you should have to call set focus on the button in your dialog, this is the intended design.

                To understand the purpose of this design, realize that if focus is elsewhere, escape may mean something completely different (like cancel current edits) and the dialog should not vanish. Think more generally about potentially multiple dialogs and other things going on on the screen and you will see why this is a correct design choice. This is true even for modal dialogs, because they may pop-up other dialogs in turn.

                Comment


                  #9
                  I understand, thank you.

                  Comment

                  Working...
                  X