DEV Community

Kevin Jump
Kevin Jump

Posted on

Early Adopter's guide to Umbraco v14 - Opening dialogs.

On thing you might want to do with your new property editor, workspace or dashboard, it get the user to pick something. That might be an document, a document type, a data type of an icon.

In 'Old School' Umbraco we did this via the editorService.

function openIconPicker() {

   var options = {
       submit: function(model) {
       close: function() {

Enter fullscreen mode Exit fullscreen mode
Old school angular dialogs

In our "brave new world" the "model manager" has taken on much of the role of the editor service so we can use that to open up-dialogs.

Gettting the modal context.

To work with modals we first have to consume the modal manager context.

constructor() {
    this.consumeContext(UMB_MODAL_MANAGER_CONTEXT, (_instance) => {
        this._modalContext = _instance;
Enter fullscreen mode Exit fullscreen mode

This will place a reference to the modal manager in our _modalContext value - we can then use that to open things!

Opening the Icon Picker.

So lets assume we have some html markup for our page, (code here) and we have a method wired up to the Click event.

Note! you could have actually just used the IconPicker property editor here. but we are showing how dialogs work, so we went the long way around

async _OpenIconPicker() {

    const pickerContext = this._modalContext?.open(UMB_ICON_PICKER_MODAL);

    const data = await pickerContext?.onSubmit();
    if (!data) return;

    if (data.color) {
        this.color = data.color as string;
    this.icon = data.icon as string;
Enter fullscreen mode Exit fullscreen mode

This opens the icon picker for us.

Open Icon picker

Opening the icon picker

Assuming we then have some markup we can display the icon.

   <uui-icon name="${this.icon}"
   <pre>${this.icon} ${this.color}</pre>
Enter fullscreen mode Exit fullscreen mode

red ship icon and button

Our super amazing icon picker

Opening anything*

So at this point we can pretty much open any of the core dialogs... if only we know there names.

Searching the source some notable modals are:


There are many many more, i did a search of the source code for _MODAL, and these are the ones that jumped out at me.

Most of these pickers will just open up if you call them, but almost all of them can also take data to change how they open.

Confirm Modal

One example of a modal that needs options to open up is the confirm modal.

the confirm model, needs a headline, content, and some context for what your buttons will say

  headline: `Are you sure`,
  content: 'Do you really want to do the thing here?',
  confirmLabel: 'Confim',
  color: 'danger',
Enter fullscreen mode Exit fullscreen mode

you pass this information in as data when you open the modal.

async openConfirm() {

  const confirmContext= this._modalContext?.open(UMB_CONFIRM_MODAL, {
    data: {
      headline: `Are you sure`,
      content: 'Do you really want to do the thing here?',
      confirmLabel: 'Confim',
      color: 'danger',

    .then(()=> {
    .catch(() => {
Enter fullscreen mode Exit fullscreen mode

And this gives you a nice confirm box. !

A Confirm dialog

Confirm box

Code for calling these dialogs is in our sample repo:


Top comments (0)