Add a native dialog element to deprecate the jQuery UI dialog

Created on 18 December 2013, over 10 years ago
Updated 1 March 2024, 4 months ago

Problem/Motivation

We are in the process of deprecating jQuery UI in core. jQueryUI dialog is among the components that need to be removed/replaced.
As mentioned in the parent issue: 🌱 [Plan] Remove jQuery UI components used by Drupal core and replace with a set of supported solutions Fixed
The OpenJS Foundation lists jQuery UI as an Emeritus project in https://openjsf.org/projects/ which is described as:

Emeritus projects are those which the maintainers feel have reached or are nearing end-of-life

This issue was originally proposed as specifically looking for a polyfill, with the following explanation:

dialog.js always aimed at using the HTML5 dialog spec. Chrome just added experimental support for dialogs in it's dev branch: http://demo.agektmr.com/dialog/

As time has moved on, it looks like a polyfill is not necessary.

We should let chrome use native dialogs when needed, it actually solves a bunch of messy issues, two of which are:
#2072037: Drupal dialog modal background z-index is set too low to reliably occlude core UI components
📌 In the Views UI, the interaction pattern of “All displays”/ “Override this display” is confusing Needs work

The problems mentioned above should absolutely be considered wile investigating what to use in place of jQueryUI dialog, but the options should be expanded to include different libraries - whatever option can best facilitate removing jQuery UI.

Proposed resolution

Add a native dialog element to the render API.
Add Umami/Claro/Olivero theme support
Convert existing core usages of jQuery UI dialog to use the native dialog.
Deprecate the jQuery UI dialog for removal in Drupal 11 or 12.

Remaining tasks

List of libraries assessed prior to the decision to use native dialogs:

If we are fortunate enough to find multiple libraries that meet these requirements, they should be compared using criteria such as: Code Style, Maturity, Responsiveness, Accessibility, UX, UI, Modularity, etc.

Libraries reviewed so far:

  • Missing requirement #2
  • Missing requirement #2
  • Missing requirement #2
  • Missing requirement #2
  • Missing requirement #2
  • Missing requirement #1
  • Missing requirement #1
  • Nyro modal (jquery) http://nyromodal.nyrodev.com/ : Meets the requirements but hasn't been updated since 2014.
  • JqModal http://jquery.iceburg.net/jqModal/#where : Meets the requirements and even has a companion resize library. Hasn't been updated since 2016
  • Missing requirements #1 and #2. Unsure about #3. Reviewed in #26.
  • sweetalert2 https://sweetalert2.github.io/: Needs review

.

Libraries to review

Implement the library

Add additional tests for important dialog use cases that aren't part of existing coverage. Before doing this review Layout Builder's test coverage as it indirectly tests a wide variety of Dialog use cases.

User interface changes

Yes, TBD.

API changes

TBD.

Data model changes

Release notes snippet

What needs to be done is making sure our API can handle native dialogs when available and that pretty much means we need to not use jQuery UI or in a very different way than today to avoid wildly different UX between native and polyfill.

📌 Task
Status

Needs work

Version

11.0 🔥

Component
Javascript 

Last updated 21 minutes ago

Created by

🇫🇷France nod_ Lille

Live updates comments and jobs are added and updated live.
  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

  • Needs accessibility review

    Used to alert the accessibility topic maintainer(s) that an issue significantly affects (or has the potential to affect) the accessibility of Drupal, and their signoff is needed (see the governance policy draft for more information). Useful links: Drupal's accessibility standards, the Drupal Core accessibility gate.

  • Needs subsystem maintainer review

    It is used to alert the maintainer(s) of a particular core subsystem that an issue significantly impacts their subsystem, and their signoff is needed (see the governance policy draft for more information). Also, if you use this tag, make sure the issue component is set to the correct subsystem. If an issue significantly impacts more than one subsystem, use needs framework manager review instead.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇷🇺Russia Chi

    Why not first introduce a new dialog API based on native dialog element? We don't have to drop all jQuery UI usage in the same patch.

  • 🇫🇷France andypost

    Native dialog is not supported on Safari still https://caniuse.com/dialog

  • 🇺🇸United States bnjmnm Ann Arbor, MI

    Native dialog is not supported on Safari still https://caniuse.com/dialog

    That's not what I'm seeing, perhaps I'm overlooking something?

  • 🇫🇷France andypost

    I was wrong, so only default styling prevents the issue

  • 🇨🇦Canada mgifford Ottawa, Ontario

    Adding WCAG SC 3.2 5.

  • 🇬🇧United Kingdom catch

    fwiw two elements seems like a good approach here, then we can switch things over in core and deprecate the jQuery UI version. It would be more like 'Add a native dialog element', 'Use the native dialog element', 'Deprecate the jQuery UI dialog'.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Late to the party here but agree with the approach in #78, came looking for this after watching IO videos and realising we no longer need the polyfill 🎉

  • 🇬🇧United Kingdom catch

    I've tried updating the issue summary and title, it's a bit tricky since there's a fair amount of change of direction in this issue over time.

    Just to expand on #78, by providing a new element, I think we should completely ignore bc for anything jQuery UI provides, whether it's the js API or markup. We will need to figure out styling in Claro/Olivero/Umami which is probably the main bit of work this creates compared to the previous approaches.

  • Open on Drupal.org →
    Environment: PHP 8.2 & MySQL 8
    last update about 1 year ago
    Not currently mergeable.
  • First commit to issue fork.
  • Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Not currently mergeable.
  • 🇦🇺Australia TinaRey

    I created a new fork and did a bit of work on this – it's a rough WIP but there's a few native dialogs now :) (added 2 screenshots)
    - created a new library dialogNative with the idea to have both in parallel and switch over bit by bit
    - changed editor and field_ui to use the new library:
    editor: on a wysiwyg field, change the text format between basic_html and full_html
    field_ui: on a content type, manage fields and attempt to delete one
    in both cases a native dialog should pop up and the buttons should work

    Notes/questions/next steps
    - The existing Drupal.dialog.showModal() and the native showModal() function have the same name, which gets slightly confusing.
    - showModal() and show() seem to be doing mostly the same thing, just one with and one without backdrop? What did I miss?
    - Atm I've just set app/core/lib/Drupal/Core/Render/MainContent/DialogRenderer.php and app/core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php to use the new native library but if we want both in parallel, this probably needs another solution. Too backend-y for me.
    - Currently ajax response data is just put out again as is, this probably needs some checks.
    - There's currently nothing for focus, tabbable, or the whole button change thing, I assume we need some of that back in.
    - Needs tests
    - Needs styling

  • last update about 1 year ago
    Custom Commands Failed
  • 🇷🇺Russia Chi

    showModal() and show() seem to be doing mostly the same thing, just one with and one without backdrop?

    They have different use cases. Modal dialog requires user action. It blocks interaction with other parts of the page. Also keyboard navigation is captured within a dialog.

  • 🇫🇷France nod_ Lille

    Very cool to see work on this again!

    1. - The existing Drupal.dialog.showModal() and the native showModal() function have the same name, which gets slightly confusing.

      That was intended, sort of like there shouldn't be an intermediate API between Drupal and the dialog API. Drupal.dialog() should just return the native dialog DOM element. The return of the Drupal.dialog() function was made to mimick the native dialog DOM API. So something along the lines of the following should be enough:

      Drupal.dialogNative = function () {
        return createDialog(element, settings);
      }

      We can figure out events later (if needed), maybe we won't need them since we'll need to call attachbehaviors somehow on the dialog contents and contrib should need to worry whether the content is in a modal or on a page. We had to do that before since jQuery has a lot of options that can be set, but that is not the case for native dialogs.

    2. - showModal() and show() seem to be doing mostly the same thing, just one with and one without backdrop? What did I miss?

      yep, same-ish. When openning a modal the rest of the content is not supposed to be "interactable": https://html.spec.whatwg.org/multipage/interaction.html#blocked-by-a-mod...

    3. - Atm I've just set app/core/lib/Drupal/Core/Render/MainContent/DialogRenderer.php and app/core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php to use the new native library but if we want both in parallel, this probably needs another solution. Too backend-y for me.

      That's ok, just need a way to test things out for now :)

    4. - Currently ajax response data is just put out again as is, this probably needs some checks. see the original Drupal.AjaxCommands.prototype.openDialog function. it uses the insert command to add html to the dialog so that behaviors are run automatically and all.
    5. - There's currently nothing for focus, tabbable, or the whole button change thing, I assume we need some of that back in. I'd test as-is for now. Seem like the focus is handled automatically by browsers and set it back to the triggering element when closing, probably nothing too bad to fix.
  • 🇷🇺Russia kostyashupenko Omsk

    Make sense to have a look in `inert` html attribute https://html.spec.whatwg.org/multipage/interaction.html#the-inert-attribute to improve keyboard navigation

  • last update 10 months ago
    Custom Commands Failed
  • @finnsky opened merge request.
  • 🇷🇸Serbia finnsky

    Hello all!

    I want to propose another approach that seems reasonable to me.
    One of the main problems with the current implementation of the dialog in Drupal is the strong binding to jQueryUI styles and markup. This leaves the developer with few options, such as changing the order of dialog elements or adding new elements to the markup.

    Currently, browser support for Web Components is the same as Drupal. https://developer.mozilla.org/en-US/docs/Web/API/Web_components

    This way we can create a web component drupal-dialog which will
    1. Create events when opening and closing.
    2. Have an extremely flexible template, easily customizable via Drupal.theme.dialogTemplate
    3. Support custom CSS properties
    4. Save element styles in dialog slots. Example with claro buttons: https://gyazo.com/b8cb363cb5854415f0b023dcbf5d7fd1

    This merge request is quite crude, but it does give some insight into the future benefits of this approach.

    Currently tested is the confirmationDialog for changing the text format on the node edit page. For the test, add content to restricted HTML and change the format to basic. https://gyazo.com/e7a6f36d8b8e96e0f7719efdbeddfed9

    Please review, Thanks!

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks, #88 might be combined with https://caniuse.com/dialog
    How can we proceed here and make the required decisions?

  • 🇷🇸Serbia finnsky

    @Anybody

    This drupal-dialog already contains HTML dialog inside.

    I think the rework order should be as follows. We have to:

    1. collect all usage of https://api.jqueryui.com/dialog/ API in the core.
    2. Make a list of options, events and methods that the new component should/can support.
    3. Write a temporary Drupal.DialogComponent that will provide this API and gradually switch Drupal to use the new component. Rewrite tests. And so on

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    I think the way forward here is what was agreed above by nod_ - start with an implementation that is based of a native dialog element and has less features than jQueryUI, add that alongside the jquery UI one and deprecate it.

    If there are missing features, we can look to implement them in follow up issues, otherwise we risk making no progress at all.

    I would encourage you to open a new issue @finnsky listing the features that native dialog doesn't provide that we may need to consider once we have a working alternative.

  • last update 9 months ago
    Custom Commands Failed
  • 🇷🇸Serbia finnsky

    Added subtask
    https://www.drupal.org/project/drupal/issues/3390549 📌 Get rid of jQuery in dialog events. Needs review

  • 🇷🇸Serbia finnsky

    Current Functional Javascript Test failure seems related to core/modules/block/js/block.js:139
    Not to this MR

  • 🇺🇸United States cosmicdreams Minneapolis/St. Paul

    Hi gang, I thought I had commented here, but it looks like I haven't.

    I worked on an idea for replacing some of the behaviors of the off-canvas dialog with the Popover Api. Firefox still doesn't have a full implementation but hides it behind a flag.

    https://www.loom.com/share/0dde75887f884ff3be3e4980601dccb9?sid=72085fcf...

  • 🇨🇦Canada mgifford Ottawa, Ontario

    @rkoller & I were talking. This advent calendar article came up You don't need JavaScript for that. Most browsers support the dialog element now.

    Not that this would be a trivial shift, but it does seem like this might be a good time to consider it.

  • 🇩🇪Germany Anybody Porta Westfalica

    For sure jQuery UI dialog becaime one of the most annoying things when handling the (on the other hand) super useful and genius use-ajax class functionality.

    This is definitely something we (the community) should push forward! Totally agree and changed the title accordingly.

  • 🇩🇪Germany Grevil

    OK, to summarize the current state of this issue, it seems, that we agreed on using the native "dialog" element through adding an additional js library called "dailogNative". And slowly but surely deprecated the use of the jquery "dialog" library in the future. @TinaRey created a first draft with many of the required changes implemented ( see MR !4187, great work btw!). @catch and @larowlan agree with that approach in #78 and #79 respectively, and many others suggest a similar approach.

    MR !397 by @bnjmnm and @_node is quite impressive but replaces the library instead of adding a new one. We might be able to use some of the for MR !4187

    The web-component approach by @finnsky also looks very promising. But should be added on top of the native dialogue library in a follow-up issue (if I understood that correctly).

    I guess we can close these two MRs then for visibility’s sake and solely focus on MR !4187.

    Reposting questions by @TinaRey in comment #83 📌 Add a native dialog element to deprecate the jQuery UI dialog Needs work

    • The existing Drupal.dialog.showModal() and the native showModal() function have the same name, which gets slightly confusing.
    • showModal() and show() seem to be doing mostly the same thing, just one with and one without backdrop? What did I miss?
    • Atm I've just set app/core/lib/Drupal/Core/Render/MainContent/DialogRenderer.php and app/core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php to use the new native library but if we want both in parallel, this probably needs another solution. Too backend-y for me.
    • Currently ajax response data is just put out again as is, this probably needs some checks.
    • There's currently nothing for focus, tabbable, or the whole button change thing, I assume we need some of that back in.
    • Needs tests
    • Needs styling

    A few of these questions were already answered by @_node in #85 📌 Add a native dialog element to deprecate the jQuery UI dialog Needs work shortly after. So let's get to it! :)

  • 🇺🇸United States cosmicdreams Minneapolis/St. Paul

    Is there a specific Slack channel where we're meeting to discuss this work?

  • 🇩🇪Germany Grevil

    @cosmicdreams I don't think there is one yet! Just saw your comment in #94 📌 Add a native dialog element to deprecate the jQuery UI dialog Needs work didn't even though about off_canvas using jquery ui as well!

  • 🇩🇪Germany Grevil

    Alright everyone, so based on the work done by @TinaRey and inspired by the jquery dialog adapter:"dialog.core.es6.js" by @bnjmnm. I worked on a contrib module the last couple of days, which "bridges" all existing Drupal.dialog() calls to use the new dialogNative library, called Dialog Native . It is still very much in a very early alpha stage and needs major testing, but creating dialog links such as:

    <a class="use-ajax" 
        data-dialog-options="{&quot;width&quot;:400}" 
        data-dialog-type="modal" 
        href="/node/1">
        First article displayed in modal dialog.
    </a>
    

    And the examples by @TinaRey:

    editor: on a wysiwyg field, change the text format between basic_html and full_html
    field_ui: on a content type, manage fields and attempt to delete one
    in both cases, a native dialog should pop up, and the buttons should work

    Already work. Although stuff like the off_canvas library is unfortunately broken, so no proper layout_builder for now...

    Eventually, we could work on the module together, until it is solid, and we are able to merge large parts into core! I can also give out maintainer ship to speed things up, if necessary! Also I am very much in favour of a dedicated slack channel. Switching out the native dialog element with implementations of the popup API mentioned by @cosmicdreams, shouldn't be a problem, but we should discuss, what benefits it would bring us!

  • 🇩🇪Germany Grevil

    I created a dedicated Slack channel, to discuss further work on Dialog Native and whether future issue work should be moved there instead: https://drupal.slack.com/archives/C06EYQU1F98

  • 🇩🇪Germany Grevil

    I dm'ed @_node, @bnjmnm and @larowlan, concerning future plans on this issue and maintainer ship for https://www.drupal.org/project/dialog_native .

  • 🇩🇪Germany diqidoq Berlin | Hamburg | New York | London | Paris

    I created a dedicated Slack channel, to discuss further work on Dialog Native

    Joined.

    concerning future plans on this issue and maintainer ship

    Feel free to add me.

  • 🇫🇷France andypost

    There's related 📌 Removal :tabbable usage in dialog.js Fixed
    which should unblock 📌 Deprecate jquery.tabbable.shim Active

Production build 0.69.0 2024