Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to set the default focus element when modal is opened. #804

Closed
mP1 opened this issue Aug 3, 2023 · 0 comments
Closed

Add the ability to set the default focus element when modal is opened. #804

mP1 opened this issue Aug 3, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request version 2.x.x Version 2.x.x issues
Milestone

Comments

@mP1
Copy link

mP1 commented Aug 3, 2023

Is your feature request related to a problem? Please describe.
I would like the ability for code to give the element that should be given focus when a Dialog opens, eg:

Dialog dialog = this.dialog
dialog.setFocusElement( this.patternTextBox.element() );
dialog.open()

Describe the solution you'd like
Currently Dialog.open discovers the first focusable element and gives focus to that.

AbstractDialog.initFocusElements is used to discover the first focusable element and stores in this a field...

    NodeList<Element> elementNodeList =
        element.querySelectorAll(
            "a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex=\"0\"]");
    List<Element> elements = elementNodeList.asList();

    if (elements.size() > 0) {
      focusElements = elements;
      firstFocusElement = focusElements.get(0);
      lastFocusElement = elements.get(elements.size() - 1);
    } else {
      lastFocusElement = contentElement.element();
    }
@mP1 mP1 changed the title Dialog.setOpenGivesFocusElement(Element) v2: Dialog.setOpenGivesFocusElement(Element) Aug 22, 2023
@vegegoku vegegoku self-assigned this Aug 27, 2023
@vegegoku vegegoku added the enhancement New feature or request label Aug 27, 2023
@vegegoku vegegoku added this to the 2.0.0-RC2 milestone Aug 27, 2023
@vegegoku vegegoku added the version 2.x.x Version 2.x.x issues label Aug 27, 2023
@vegegoku vegegoku changed the title v2: Dialog.setOpenGivesFocusElement(Element) Add the ability to set the default focus element when modal is opened. Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request version 2.x.x Version 2.x.x issues
Projects
Status: Done
Development

No branches or pull requests

2 participants