Class Dialog
- All Implemented Interfaces:
AttachNotifier
,DetachNotifier
,HasComponents
,HasElement
,HasEnabled
,HasSize
,HasStyle
,HasTheme
,HasThemeVariant<DialogVariant>
,Serializable
Dialogs can be made modal or non-modal. A modal Dialog blocks the user from interacting with the rest of the user interface while the Dialog is open, as opposed to a non-modal Dialog, which does not block interaction.
Dialogs can be made draggable and resizable. When draggable, the user is able to move them around using a pointing device. It is recommended to make non-modal Dialogs draggable so that the user can interact with content that might otherwise be obscured by the Dialog. A resizable Dialog allows the user to resize the Dialog by dragging from the edges of the Dialog with a pointing device. Dialogs are not resizable by default.
Dialogs automatically become scrollable when their content overflows. Custom scrollable areas can be created using the Scroller component.
Best Practices:
Dialogs are disruptive by nature and should be used sparingly. Do not use
them to communicate nonessential information, such as success messages like
“Logged in”, “Copied”, and so on. Instead, use Notifications when
appropriate.
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
`vaadin-dialog-close-action` is sent when the user clicks outside the overlay or presses the escape key.static final class
Class for adding and removing components to the footer part of a dialog.static final class
Class for adding and removing components to the header part of a dialog.static class
`resize` event is sent when the user finishes resizing the overlay.static class
opened-changed
event is sent when the overlay opened state changes. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(Collection<Component> components) Adds the given components into this dialog.addAttachListener
(ComponentEventListener<AttachEvent> listener) Adds a attach listener to this component.void
addComponentAtIndex
(int index, Component component) Adds the given component into this dialog at the given index.addDetachListener
(ComponentEventListener<DetachEvent> listener) Adds a detach listener to this component.Add a listener that controls whether the dialog should be closed or not.Add a lister for event fired by theopened-changed
events.Adds a listener that is called after user finishes resizing the overlay.void
close()
Closes the dialog.protected String
Set thearia-label
attribute for assistive technologies like screen readers.Gets the set of CSS class names used for this element.Gets the object from which components can be added or removed from the dialog footer area.Gets the object from which components can be added or removed from the dialog header area.Gets the title set for the dialog header.Gets the height defined for the component.Gets the max-height defined for the component.Gets the max-width defined for the component.Gets the min-height defined for the component.Gets the min-width defined for the component.getStyle()
Gets the style instance for managing inline styles for the element of this component.getWidth()
Gets the width defined for the component.boolean
Gets whether this dialog can be closed by hitting the esc-key or not.boolean
Gets whether this dialog can be closed by clicking outside of it or not.boolean
Gets whether dialog is enabled to be dragged or not.boolean
isModal()
Gets whether component is set as modal or modeless dialog.boolean
isOpened()
Gets the open state from the dialog.boolean
Gets whether dialog is enabled to be resized or not.protected void
onAttach
(AttachEvent attachEvent) Called when the component is attached to a UI.void
open()
Opens the dialog.protected void
setAriaLabel
(String ariaLabel) Set thearia-label
attribute for assistive technologies like screen readers.void
setClassName
(String className) Sets the CSS class names of the dialog overlay element.void
setCloseOnEsc
(boolean closeOnEsc) Sets whether this dialog can be closed by hitting the esc-key or not.void
setCloseOnOutsideClick
(boolean closeOnOutsideClick) Sets whether this dialog can be closed by clicking outside of it or not.void
setDraggable
(boolean draggable) Sets whether dialog is enabled to be dragged by the user or not.void
setHeaderTitle
(String title) Sets the title to be rendered on the dialog header.void
Sets the height of the component.void
setMaxHeight
(String value) Sets the max-height of the component.void
setMaxWidth
(String value) Sets the max-width of the component.void
setMinHeight
(String value) Sets the min-height of the component.void
setMinWidth
(String value) Sets the min-width of the component.void
setModal
(boolean modal) Sets whether component will open modal or modeless dialog.void
setOpened
(boolean opened) Opens or closes the dialog.void
setResizable
(boolean resizable) Sets whether dialog can be resized by user or not.void
setVisible
(boolean visible) Set the visibility of the dialog.void
Sets the width of the component.Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.component.HasComponents
add, add, addComponentAsFirst, remove, remove, removeAll
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeightUnit, getWidthUnit, setHeight, setHeightFull, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidthFull
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, hasClassName, removeClassName, removeClassNames, setClassName
Methods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
Methods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, removeThemeVariants
-
Constructor Details
-
Dialog
public Dialog()Creates an empty dialog. -
Dialog
Creates a dialog with given components inside.- Parameters:
components
- the components inside the dialog- See Also:
-
Dialog
Creates a dialog with given title.- Parameters:
title
- the title of the component
-
Dialog
Creates a dialog with given title and components inside.- Parameters:
title
- the title of the componentcomponents
- the components inside the dialog
-
-
Method Details
-
setWidth
Description copied from interface:HasSize
Sets the width of the component.The width should be in a format understood by the browser, e.g. "100px" or "2.5em".
If the provided
width
value is null then width is removed. -
setMinWidth
Description copied from interface:HasSize
Sets the min-width of the component.The width should be in a format understood by the browser, e.g. "100px" or "2.5em".
If the provided
minWidth
value is null then min-width is removed.- Specified by:
setMinWidth
in interfaceHasSize
- Parameters:
value
- the min-width value (ifnull
, the property will be removed)
-
setMaxWidth
Description copied from interface:HasSize
Sets the max-width of the component.The width should be in a format understood by the browser, e.g. "100px" or "2.5em".
If the provided
maxWidth
value is null then max-width is removed.- Specified by:
setMaxWidth
in interfaceHasSize
- Parameters:
value
- the max-width value (ifnull
, the property will be removed)
-
setHeight
Description copied from interface:HasSize
Sets the height of the component.The height should be in a format understood by the browser, e.g. "100px" or "2.5em".
If the provided
height
value is null then height is removed. -
setMinHeight
Description copied from interface:HasSize
Sets the min-height of the component.The height should be in a format understood by the browser, e.g. "100px" or "2.5em".
If the provided
minHeight
value is null then min-height is removed.- Specified by:
setMinHeight
in interfaceHasSize
- Parameters:
value
- the min-height value (ifnull
, the property will be removed)
-
setMaxHeight
Description copied from interface:HasSize
Sets the max-height of the component.The height should be in a format understood by the browser, e.g. "100px" or "2.5em".
If the provided
maxHeight
value is null then max-height is removed.- Specified by:
setMaxHeight
in interfaceHasSize
- Parameters:
value
- the max-height value (ifnull
, the property will be removed)
-
getWidth
Description copied from interface:HasSize
Gets the width defined for the component.Note that this does not return the actual size of the component but the width which has been set using
HasSize.setWidth(String)
. -
getMinWidth
Description copied from interface:HasSize
Gets the min-width defined for the component.Note that this does not return the actual size of the component but the min-width which has been set using
HasSize.setMinWidth(String)
.- Specified by:
getMinWidth
in interfaceHasSize
- Returns:
- the min-width which has been set for the component
-
getMaxWidth
Description copied from interface:HasSize
Gets the max-width defined for the component.Note that this does not return the actual size of the component but the max-width which has been set using
HasSize.setMaxWidth(String)
.- Specified by:
getMaxWidth
in interfaceHasSize
- Returns:
- the max-width which has been set for the component
-
getHeight
Description copied from interface:HasSize
Gets the height defined for the component.Note that this does not return the actual size of the component but the height which has been set using
HasSize.setHeight(String)
. -
getMinHeight
Description copied from interface:HasSize
Gets the min-height defined for the component.Note that this does not return the actual size of the component but the min-height which has been set using
HasSize.setMinHeight(String)
.- Specified by:
getMinHeight
in interfaceHasSize
- Returns:
- the min-height which has been set for the component
-
getMaxHeight
Description copied from interface:HasSize
Gets the max-height defined for the component.Note that this does not return the actual size of the component but the max-height which has been set using
HasSize.setMaxHeight(String)
.- Specified by:
getMaxHeight
in interfaceHasSize
- Returns:
- the max-height which has been set for the component
-
addDialogCloseActionListener
public Registration addDialogCloseActionListener(ComponentEventListener<Dialog.DialogCloseActionEvent> listener) Add a listener that controls whether the dialog should be closed or not.The listener is informed when the user wants to close the dialog by clicking outside the dialog, or by pressing escape. Then you can decide whether to close or to keep opened the dialog. It means that dialog won't be closed automatically unless you call
close()
method explicitly in the listener implementation.NOTE: adding this listener changes behavior of the dialog. Dialog is closed automatically in case there are no any close listeners. And the
close()
method should be called explicitly to close the dialog in case there are close listeners.- Parameters:
listener
- the listener to add- Returns:
- registration for removal of listener
- See Also:
-
addResizeListener
Adds a listener that is called after user finishes resizing the overlay. It is called only if resizing is enabled (seesetResizable(boolean)
).Note: By default, the component will sync the width/height values after every resizing.
- Parameters:
listener
- the listener to add- Returns:
- registration for removal of listener
-
add
Adds the given components into this dialog.The elements in the DOM will not be children of the
<vaadin-dialog>
element, but will be inserted into an overlay that is attached into the<body>
.- Specified by:
add
in interfaceHasComponents
- Parameters:
components
- the components to add
-
addComponentAtIndex
Adds the given component into this dialog at the given index.The element in the DOM will not be child of the
<vaadin-dialog>
element, but will be inserted into an overlay that is attached into the<body>
.- Specified by:
addComponentAtIndex
in interfaceHasComponents
- Parameters:
index
- the index, where the component will be added.component
- the component to add
-
isCloseOnEsc
public boolean isCloseOnEsc()Gets whether this dialog can be closed by hitting the esc-key or not.By default, the dialog is closable with esc.
- Returns:
true
if this dialog can be closed with the esc-key,false
otherwise
-
setCloseOnEsc
public void setCloseOnEsc(boolean closeOnEsc) Sets whether this dialog can be closed by hitting the esc-key or not.By default, the dialog is closable with esc.
- Parameters:
closeOnEsc
-true
to enable closing this dialog with the esc-key,false
to disable it
-
isCloseOnOutsideClick
public boolean isCloseOnOutsideClick()Gets whether this dialog can be closed by clicking outside of it or not.By default, the dialog is closable with an outside click.
- Returns:
true
if this dialog can be closed by an outside click,false
otherwise
-
setCloseOnOutsideClick
public void setCloseOnOutsideClick(boolean closeOnOutsideClick) Sets whether this dialog can be closed by clicking outside of it or not.By default, the dialog is closable with an outside click.
- Parameters:
closeOnOutsideClick
-true
to enable closing this dialog with an outside click,false
to disable it
-
open
public void open()Opens the dialog.Note: You don't need to add the dialog component anywhere before opening it. Since
<vaadin-dialog>
's location in the DOM doesn't really matter, opening a dialog will automatically add it to the<body>
if necessary. -
close
public void close()Closes the dialog.Note: This method also removes the dialog component from the DOM after closing it, unless you have added the component manually.
-
setModal
public void setModal(boolean modal) Sets whether component will open modal or modeless dialog.Note: When dialog is set to be modeless, then it's up to you to provide means for it to be closed (eg. a button that calls
close()
). The reason being that a modeless dialog allows user to interact with the interface under it and won't be closed by clicking outside or the ESC key.- Parameters:
modal
-false
to enable dialog to open as modeless modal,true
otherwise.
-
isModal
public boolean isModal()Gets whether component is set as modal or modeless dialog.- Returns:
true
if modal dialog (default),false
otherwise.
-
setDraggable
public void setDraggable(boolean draggable) Sets whether dialog is enabled to be dragged by the user or not.To allow an element inside the dialog to be dragged by the user (for instance, a header inside the dialog), a class
"draggable"
can be added to it (seeHasStyle.addClassName(String)
).Note: If draggable is enabled and dialog is opened without first being explicitly attached to a parent, then it won't restore its last position in the case the user closes and opens it again. Reason being that a self attached dialog is removed from the DOM when it's closed and position is not synched.
- Parameters:
draggable
-true
to enable dragging of the dialog,false
otherwise
-
isDraggable
public boolean isDraggable()Gets whether dialog is enabled to be dragged or not.- Returns:
true
if dragging is enabled,false
otherwise (default).
-
setResizable
public void setResizable(boolean resizable) Sets whether dialog can be resized by user or not.- Parameters:
resizable
-true
to enabled resizing of the dialog,false
otherwise.
-
isResizable
public boolean isResizable()Gets whether dialog is enabled to be resized or not.- Returns:
true
if resizing is enabled,falsoe
otherwiser (default).
-
setHeaderTitle
Sets the title to be rendered on the dialog header.- Parameters:
title
- title to be rendered
-
getHeaderTitle
Gets the title set for the dialog header.- Returns:
- the title or an empty string, if a header title is not defined.
-
getHeader
Gets the object from which components can be added or removed from the dialog header area. The header is displayed only if there's agetHeaderTitle()
or at least one component added withDialog.DialogHeaderFooter.add(Component...)
.- Returns:
- the header object
-
setVisible
public void setVisible(boolean visible) Set the visibility of the dialog.For a modal dialog the server-side modality will be removed when dialog is not visible so that interactions can be made in the application.
- Overrides:
setVisible
in classComponent
- Parameters:
visible
- dialog visibility- See Also:
-
setOpened
public void setOpened(boolean opened) Opens or closes the dialog.Note: You don't need to add the dialog component anywhere before opening it. Since
<vaadin-dialog>
's location in the DOM doesn't really matter, opening a dialog will automatically add it to the<body>
if necessary.- Parameters:
opened
-true
to open the dialog,false
to close it
-
isOpened
Gets the open state from the dialog.- Returns:
- the
opened
property from the dialog
-
addOpenedChangeListener
public Registration addOpenedChangeListener(ComponentEventListener<Dialog.OpenedChangeEvent> listener) Add a lister for event fired by theopened-changed
events.- Parameters:
listener
- the listener to add- Returns:
- a Registration for removing the event listener
-
addAttachListener
Adds a attach listener to this component.Note: To listen for opening the dialog, you should use
addOpenedChangeListener(ComponentEventListener)
.- Specified by:
addAttachListener
in interfaceAttachNotifier
- Parameters:
listener
- the listener to add, notnull
- Returns:
- a handle that can be used for removing the listener
-
addDetachListener
Adds a detach listener to this component.Note: To listen for closing the dialog, you should use
addOpenedChangeListener(ComponentEventListener)
, as the component is not necessarily removed from the DOM when closing.- Specified by:
addDetachListener
in interfaceDetachNotifier
- Parameters:
listener
- the listener to add, notnull
- Returns:
- a handle that can be used for removing the listener
-
onAttach
Description copied from class:Component
Called when the component is attached to a UI.This method is invoked before the
Make sure to callAttachEvent
is fired for the component.super.onAttach
when overriding this method. -
getAriaLabel
Set thearia-label
attribute for assistive technologies like screen readers. Anundefined
value for this property (the default) means that thearia-label
attribute is not present at all.This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
- Returns:
- the
ariaLabel
property from the webcomponent
-
setAriaLabel
Set thearia-label
attribute for assistive technologies like screen readers. Anundefined
value for this property (the default) means that thearia-label
attribute is not present at all.- Parameters:
ariaLabel
- the String value to set
-
setClassName
Sets the CSS class names of the dialog overlay element. This method overwrites any previous set class names.- Specified by:
setClassName
in interfaceHasStyle
- Parameters:
className
- a space-separated string of class names to set, ornull
to remove all class names
-
getClassNames
Description copied from interface:HasStyle
Gets the set of CSS class names used for this element. The returned set can be modified to add or remove class names. The contents of the set is also reflected in the value of theclass
attribute.Despite the name implying a list being returned, the return type is actually a
Set
since the in-browser return value behaves like aSet
in Java.- Specified by:
getClassNames
in interfaceHasStyle
- Returns:
- a list of class names, never
null
- See Also:
-
getStyle
Description copied from interface:HasStyle
Gets the style instance for managing inline styles for the element of this component.- Specified by:
getStyle
in interfaceHasStyle
- Returns:
- the style object for the element, not
null
- Throws:
UnsupportedOperationException
- Dialog does not support adding styles to overlay
-