Dialogs

Overview

A dialog is a small window that opens on top of a program to show something for a short time: a message, a warning, a few settings, or a question. When the person is done, the dialog closes and they go back to what they were doing. In Quorum, a Dialog holds a page, the same kind of page that a Form uses, so you fill a dialog with labels and buttons the same way you fill a Form. In this tutorial, you will build a dialog, open it from a button on a Form, close it, give it more than one page, and make sure it works well with a keyboard and a screen reader.

Goals

You have the following goals for this tutorial:

By the end of this lesson, you can

  • Make your own dialog class that inherits from Dialog
  • Fill a dialog with a page of labels and buttons using InitializeDefaultPage
  • Open and close a dialog with Show, Hide and the Escape key
  • Move between pages in a dialog with SetCurrentPage
  • Evaluate the reasons behind a real law, the GDPR, that shapes the consent dialogs many websites show

Warm up

Think of a dialog you have used recently. Maybe a program asked "Save changes before closing?", or a game showed a help box. What was it asking you? Could you use the rest of the program while it was open? How did you close it? If you use a keyboard or a screen reader, where did your focus go when it opened, and where did it go when it closed?

Vocabulary

You will be learning about the following vocabulary words:

Vocabulary
TermDefinition
DialogA small window that opens on top of a program to show a message or ask for input for a short time.
ModalA modal dialog blocks the rest of the program until it is closed. Clicks outside it do nothing.
PageA container that stacks labels and buttons in rows. Forms and dialogs both use pages.
Top barThe strip across the top of a dialog. It shows the dialog's name and a close button.
FocusThe control that the keyboard is using right now. A screen reader reads the control that has the focus.
CookieA small piece of text that a website stores in your web browser, formatted to keep data about you. The name is strange, but a cookie is just text.

New Code to Learn

You will be using the following new pieces of code:

New Code to Learn
Quorum CodeCode ExampleExplanation
class ... is Dialogclass HelpDialog is DialogMakes a new kind of dialog that has everything a Dialog has.
InitializeDefaultPage()Page page = InitializeDefaultPage()Creates an empty page inside the dialog and returns it so you can add labels and buttons to it.
Show()dialog:Show()Opens the dialog. Quorum then calls the dialog's OnShow action.
Hide()dialog:Hide()Closes the dialog. Quorum then calls the dialog's OnHide action.
SetModal(boolean value)SetModal(true)If true, the rest of the program ignores the mouse and keyboard until the dialog is closed.
SetCurrentPage(Page page)SetCurrentPage(secondPage)Replaces the page the dialog is showing with another page.
ApplyDefaultStyleToPage(Page page)ApplyDefaultStyleToPage(secondPage)Gives a page you made yourself the same size and border as the default page.
SetTopBarVisible(boolean enable)SetTopBarVisible(false)Shows or hides the top bar. Call it before the dialog is shown.
GetFirstFocusableItem()page:GetFirstFocusableItem()Returns the first control on a page that can take the focus.
Focus()item:Focus()Moves the keyboard focus to this control.

CSTA Standards

This tutorial covers the following CSTA standards:

For teachers · 2026 CSTA K–12 Computer Science Standards

HS-PRO-PD-12

High School · Programming

Create a modular program that uses procedures, external libraries, or objects to improve reusability and readability.

Also in 9 other lessons

MS-PRO-PD-12

Middle School · Programming

Use a procedure to structure code for clarity and reusability.

Also in 5 other lessons

S1-SWD-UX-04

Specialty I · Software Development

Refine a user interface design using accessibility and responsive design tools.

Also in 13 other lessons

HS-SYS-IM-36

High School · Systems & Security

Evaluate the rationale behind a law or policy governing the design and use of computing systems.

Also in 1 other lesson

Every standard, and the lessons that cover it

Explore

What is in a dialog

Every Quorum dialog has two parts:

  • a top bar, which shows the dialog's name and an X button that closes it;
  • a page under the top bar, which holds everything else.

A page stacks what you add to it in rows, from top to bottom. If you have read the Forms and Pages tutorials, this is the same Page you used there, with the same AddLabel and AddButton actions.

A dialog can also be modal. While a modal dialog is open, clicks and key presses outside it are ignored, so the person has to deal with the dialog first.

Making a dialog class

Add a new class named HelpDialog.quorum. Your class inherits from Dialog, so it gets all of Dialog's actions. (The Inheritance tutorial explains more about inheritance.)

use Libraries.Interface.Controls.Dialog
use Libraries.Interface.Controls.Button
use Libraries.Interface.Forms.Page
use Libraries.Interface.Behaviors.Controls.DialogHideBehavior

class HelpDialog is Dialog
    DialogHideBehavior closeBehavior

    action Setup
        SetName("Help")
        SetDescription("Explains how to use the app")
        SetModal(true)
        SetPixelWidth(400)
        SetPixelHeight(180)

        closeBehavior:SetDialog(me)
        SetBehavior(closeBehavior)

        Page page = InitializeDefaultPage()
        page:AddLabel("Help text", "Press Tab to move between controls. Press Space to press a button.")
        Button closeButton = page:AddButton("Close")
        closeButton:SetDescription("Closes the help dialog")
        closeButton:SetBehavior(closeBehavior)
    end

    action OnShow
        GetDefaultPage():GetFirstFocusableItem():Focus()
    end

    action OnHide
        output "The help dialog closed."
    end
end

Here is what each part does:

  • SetName("Help") gives the dialog its name. The name is shown in the top bar, and a screen reader reads it when the dialog opens.
  • SetPixelWidth and SetPixelHeight give the dialog its size. Set the size before you call InitializeDefaultPage, because the page fits itself to the dialog.
  • DialogHideBehavior is a behavior that comes with Quorum. When it runs, it closes the dialog you gave it with SetDialog. Here it is used twice:
    • on the Close button;
    • with the dialog's own SetBehavior, which runs when the person presses Enter and the focus is not on a button.
  • InitializeDefaultPage() creates an empty page, puts it in the dialog, and returns it. Then you add a label and a button to the page, just as on a Form's page. As on a Form, the first name you give AddLabel names the label, and the second is the text it shows.
  • OnShow runs every time the dialog opens. It moves the focus to the first thing on the page, which is the label. A screen reader user hears the help message first, and can press Tab to reach the Close button. A dialog doesn't move the focus into itself, so this one line does it: GetFirstFocusableItem finds the first control on the page, and Focus gives it the focus. The Focus tutorial covers the focus in full.
  • OnHide runs every time the dialog closes.

Opening the dialog from a page

A dialog is not added to a page. Instead, something calls its Show action. Here, a button on the Form's page does it. Add a class named ShowDialogBehavior.quorum:

use Libraries.Interface.Behaviors.Behavior
use Libraries.Interface.Events.BehaviorEvent
use Libraries.Interface.Controls.Dialog

class ShowDialogBehavior is Behavior
    Dialog dialog = undefined

    action SetDialog(Dialog dialog)
        me:dialog = dialog
    end

    action Run(BehaviorEvent event)
        dialog:Show()
    end
end

Because dialog has the type Dialog, this behavior can open any dialog, including the ones you make later in this tutorial.

Now replace Main.quorum:

use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Controls.Button

Form form
Page page = form:GetMainPage()

HelpDialog help
help:Setup()

ShowDialogBehavior showHelp
showHelp:SetDialog(help)

page:AddLabel("Intro", "Press the Help button to learn how this app works.")
Button button = page:AddButton("Help")
button:SetDescription("Opens the help dialog")
button:SetBehavior(showHelp)

form:Display()

Run the program, press Tab to reach the Help button, and press Space. The dialog opens in the middle of the window. You can close it four ways:

  • press Tab to reach the Close button, then press Space or Enter;
  • press Enter while the help text has the focus, which runs the dialog's behavior;
  • press Escape, which closes any dialog;
  • click the X in the top bar.

When the dialog closes, the focus goes back to the Help button, the control that had it before the dialog opened. A keyboard user is right where they left off.

More than one page

Some dialogs walk a person through steps, like a setup screen with Next and Back buttons. A dialog can do this by switching pages:

  • InitializeDefaultPage makes the first page.
  • For each other page, make a StackedRowPage yourself, and call ApplyDefaultStyleToPage so it gets the same size and border.
  • SetCurrentPage swaps the page the dialog shows.

Add a class named WelcomeDialog.quorum:

use Libraries.Interface.Controls.Dialog
use Libraries.Interface.Controls.Button
use Libraries.Interface.Forms.Page
use Libraries.Interface.Pages.StackedRowPage
use Libraries.Interface.Behaviors.Controls.DialogHideBehavior

class WelcomeDialog is Dialog
    Page firstPage = undefined
    StackedRowPage secondPage
    DialogHideBehavior closeBehavior
    NextPageBehavior nextBehavior

    action Setup
        SetName("Welcome")
        SetDescription("Two steps that explain the app")
        SetModal(true)
        SetPixelWidth(400)
        SetPixelHeight(180)

        closeBehavior:SetDialog(me)
        nextBehavior:SetDialog(me)

        firstPage = InitializeDefaultPage()
        firstPage:AddLabel("Step 1", "Step 1 of 2: Welcome to the app!")
        Button nextButton = firstPage:AddButton("Next")
        nextButton:SetDescription("Goes to step 2")
        nextButton:SetBehavior(nextBehavior)

        ApplyDefaultStyleToPage(secondPage)
        secondPage:AddLabel("Step 2", "Step 2 of 2: Use the Help button whenever you get stuck.")
        Button doneButton = secondPage:AddButton("Done")
        doneButton:SetDescription("Closes the welcome dialog")
        doneButton:SetBehavior(closeBehavior)
    end

    action ShowSecondPage
        SetCurrentPage(secondPage)
        SetBehavior(closeBehavior)
        secondPage:GetFirstFocusableItem():Focus()
    end

    action OnShow
        SetCurrentPage(firstPage)
        SetBehavior(nextBehavior)
        firstPage:GetFirstFocusableItem():Focus()
    end
end

The Next button needs a behavior that calls ShowSecondPage. Add a class named NextPageBehavior.quorum:

use Libraries.Interface.Behaviors.Behavior
use Libraries.Interface.Events.BehaviorEvent

class NextPageBehavior is Behavior
    WelcomeDialog dialog = undefined

    action SetDialog(WelcomeDialog dialog)
        me:dialog = dialog
    end

    action Run(BehaviorEvent event)
        dialog:ShowSecondPage()
    end
end

To try it, change Main.quorum so the button opens a WelcomeDialog instead:

use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Controls.Button

Form form
Page page = form:GetMainPage()

WelcomeDialog welcome
welcome:Setup()

ShowDialogBehavior showWelcome
showWelcome:SetDialog(welcome)

page:AddLabel("Intro", "New here? Press the Welcome button.")
Button button = page:AddButton("Welcome")
button:SetDescription("Opens the welcome dialog")
button:SetBehavior(showWelcome)

form:Display()

Some things to notice:

  • OnShow always goes back to the first page, so the dialog starts over each time it opens.
  • Each time the page changes, the focus moves to the first thing on the new page. Without this, a keyboard or screen reader user would be left on a button that is no longer on the screen.
  • Each label says "Step 1 of 2" or "Step 2 of 2", so everyone knows how many steps there are.
  • SetBehavior changes what Enter does on each page: Next on the first page, Done on the second.
Blocks

Hiding the top bar

Sometimes you don't want a top bar, for example on a splash screen when a program starts. Call SetTopBarVisible(false) in Setup, before the dialog is shown:

SetTopBarVisible(false)

Without a top bar, there is no X button, and the name is not shown on the screen. So:

  • always give the dialog a button that closes it;
  • still call SetName, because a screen reader uses the name even when it is not shown;
  • call SetTopBarVisible before InitializeDefaultPage. The page makes room for the top bar only if the top bar is turned on.

Escape still closes a dialog that has no top bar.

Dialogs and the keyboard

Here is a summary of the keys a dialog understands:

  • Escape closes the dialog.
  • Enter runs the behavior you gave the dialog with SetBehavior, unless the focus is on a button, which Enter presses instead. If you didn't give the dialog a behavior, Enter does nothing on the dialog itself.
  • Tab and Shift+Tab move between the labels and buttons on the page.

A good dialog always moves the focus into itself in OnShow. If it doesn't, the focus stays on the control behind the dialog, and a keyboard user can't reach the dialog at all. When the dialog closes, Quorum gives the focus back to the control that had it before.

Dialogs and the law: the GDPR

Many websites open a dialog the first time you visit, asking whether they may use cookies. Cookie is a strange name for something simple: a cookie is a small piece of text that a website stores in your web browser, formatted so the site can keep data about you, such as whether you are signed in or which pages you have visited. The next time you visit, the browser sends the cookie back to the site. One reason for the dialog is a law. The European Union's General Data Protection Regulation (GDPR), Regulation (EU) 2016/679, sets rules for how organizations handle personal data about people in the EU (EUR-Lex). A few of its rules:

  • Cookies can identify people. The GDPR notes that people can be linked to "online identifiers," such as "cookie identifiers," that can be used to build profiles of them (Recital 30).
  • Consent must be real. Consent means a "freely given, specific, informed and unambiguous" agreement, shown "by a statement or by a clear affirmative action" (Article 4(11)).
  • Saying no must be as easy as saying yes. People may withdraw consent at any time, and "it shall be as easy to withdraw as to give consent" (Article 7(3)).
  • Children need a parent. For online services offered directly to children, a child under 16 needs a parent's consent. Each EU country may lower that age, but not below 13 (Article 8(1)).
  • People can ask for their data to be erased in certain cases, such as when it is no longer needed or when they withdraw consent (Article 17).
  • Breaking the rules is costly. The largest fines are up to 20 million euros or 4% of a company's total worldwide yearly turnover (Article 83(5)).

The rule that a website must ask before storing cookies on your device comes from a related EU law, the ePrivacy Directive (Article 5(3)). The GDPR sets what counts as real consent (EUR-Lex).

Engage

In this activity, you build a consent dialog that follows the GDPR, then judge the reasons behind the law. Use the rules in "Dialogs and the law: the GDPR" as your evidence.

  1. Plan it. On paper or with physical manipulatives, design a cookie consent dialog for a made-up website. Write its name, its message and its buttons. For each GDPR rule listed above, write how your dialog follows it. For example, Article 7(3) means saying no can't take more steps than saying yes, and Article 4(11) means nothing can be agreed to for the person in advance.
  2. Build it. Make the dialog as a class that inherits from Dialog, using InitializeDefaultPage, AddLabel and AddButton, and open it from a button on a Form's page, like the HelpDialog example. Test that you can open it, read it, choose an answer and close it with only the keyboard.
  3. Judge the law. Answer in a few sentences each:
    • What problem does each rule try to solve, and who does it protect?
    • What does each rule cost: for people using websites, for small companies, for large ones?
    • Is a dialog a good way to get real consent, or do people click whatever ends the interruption? What evidence would help you decide?
    • Compare one GDPR rule with COPPA, the US rule for children's data from the Pages tutorial. Which approach do you think works better, and why?

Wrap up

Dialogs interrupt people. When is that a good thing, and when is it annoying? Think of one dialog you have used that should not have been a dialog at all. What could the program have done instead?

The next tutorial covers the Option Dialog, a ready-made dialog that asks a yes or no question.