Class Dialog
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.dialog.GeneratedVaadinDialog<Dialog>
-
- com.vaadin.flow.component.dialog.Dialog
-
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasComponents,HasElement,HasEnabled,HasSize,HasStyle,HasTheme,Serializable
@JsModule("./dialogConnector.js") @JsModule("./flow-component-renderer.js") public class Dialog extends GeneratedVaadinDialog<Dialog> implements HasComponents, HasSize, HasTheme, HasStyle
A Dialog is a small window that can be used to present information and user interface elements in an overlay.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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDialog.DialogCloseActionEvent`vaadin-dialog-close-action` is sent when the user clicks outside the overlay or presses the escape key.static classDialog.DialogFooterClass for adding and removing components to the footer part of a dialog.static classDialog.DialogHeaderClass for adding and removing components to the header part of a dialog.static classDialog.DialogResizeEvent`resize` event is sent when the user finishes resizing the overlay.static classDialog.OpenedChangeEvent<T extends GeneratedVaadinDialog<T>>
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Component... components)Adds the given components into this dialog.RegistrationaddAttachListener(ComponentEventListener<AttachEvent> listener)Adds a attach listener to this component.voidaddComponentAtIndex(int index, Component component)Adds the given component into this dialog at the given index.RegistrationaddDetachListener(ComponentEventListener<DetachEvent> listener)Adds a detach listener to this component.RegistrationaddDialogCloseActionListener(ComponentEventListener<Dialog.DialogCloseActionEvent> listener)Add a listener that controls whether the dialog should be closed or not.RegistrationaddOpenedChangeListener(ComponentEventListener<Dialog.OpenedChangeEvent<Dialog>> listener)Add a lister for event fired by theopened-changedevents.RegistrationaddResizeListener(ComponentEventListener<Dialog.DialogResizeEvent> listener)Adds a listener that is called after user finishes resizing the overlay.voidaddThemeVariants(DialogVariant... variants)Adds theme variants to the component.voidclose()Closes the dialog.Stream<Component>getChildren()Gets the child components of this component.Dialog.DialogFootergetFooter()Gets the object from which components can be added or removed from the dialog footer area.Dialog.DialogHeadergetHeader()Gets the object from which components can be added or removed from the dialog header area.StringgetHeaderTitle()Gets the title set for the dialog header.StringgetHeight()Gets the height defined for the component.StringgetMaxHeight()Gets the max-height defined for the component.StringgetMaxWidth()Gets the max-width defined for the component.StringgetMinHeight()Gets the min-height defined for the component.StringgetMinWidth()Gets the min-width defined for the component.StylegetStyle()Gets the style instance for managing inline styles for the element of this component.StringgetWidth()Gets the width defined for the component.booleanisCloseOnEsc()Gets whether this dialog can be closed by hitting the esc-key or not.booleanisCloseOnOutsideClick()Gets whether this dialog can be closed by clicking outside of it or not.booleanisDraggable()Gets whether dialog is enabled to be dragged or not.booleanisModal()Gets whether component is set as modal or modeless dialog.booleanisOpened()Gets the open state from the dialog.booleanisResizable()Gets whether dialog is enabled to be resized or not.protected voidonAttach(AttachEvent attachEvent)Called when the component is attached to a UI.voidopen()Opens the dialog.voidremove(Component... components)Removes the given child components from this component.voidremoveAll()Removes all contents from this component, this includes child components, text content as well as child elements that have been added directly to this component using theElementAPI.voidremoveThemeVariants(DialogVariant... variants)Removes theme variants from the component.voidsetCloseOnEsc(boolean closeOnEsc)Sets whether this dialog can be closed by hitting the esc-key or not.voidsetCloseOnOutsideClick(boolean closeOnOutsideClick)Sets whether this dialog can be closed by clicking outside of it or not.voidsetDraggable(boolean draggable)Sets whether dialog is enabled to be dragged by the user or not.voidsetHeaderTitle(String title)Sets the title to be rendered on the dialog header.voidsetHeight(String value)Sets the height of the component.voidsetMaxHeight(String value)Sets the max-height of the component.voidsetMaxWidth(String value)Sets the max-width of the component.voidsetMinHeight(String value)Sets the min-height of the component.voidsetMinWidth(String value)Sets the min-width of the component.voidsetModal(boolean modal)Sets whether component will open modal or modeless dialog.voidsetOpened(boolean opened)Opens or closes the dialog.voidsetResizable(boolean resizable)Sets whether dialog can be resized by user or not.voidsetVisible(boolean visible)Set the visibility of the dialog.voidsetWidth(String value)Sets the width of the component.-
Methods inherited from class com.vaadin.flow.component.dialog.GeneratedVaadinDialog
getAriaLabelString, isOpenedBoolean, setAriaLabel
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, 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
-
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, getClassNames, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Methods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
-
-
-
-
Constructor Detail
-
Dialog
public Dialog()
Creates an empty dialog.
-
Dialog
public Dialog(Component... components)
Creates a dialog with given components inside.- Parameters:
components- the components inside the dialog- See Also:
add(Component...)
-
-
Method Detail
-
setWidth
public void setWidth(String value)
Description copied from interface:HasSizeSets 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
widthvalue is null then width is removed.
-
setMinWidth
public void setMinWidth(String value)
Description copied from interface:HasSizeSets 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
minWidthvalue is null then min-width is removed.- Specified by:
setMinWidthin interfaceHasSize- Parameters:
value- the min-width value (ifnull, the property will be removed)
-
setMaxWidth
public void setMaxWidth(String value)
Description copied from interface:HasSizeSets 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
maxWidthvalue is null then max-width is removed.- Specified by:
setMaxWidthin interfaceHasSize- Parameters:
value- the max-width value (ifnull, the property will be removed)
-
setHeight
public void setHeight(String value)
Description copied from interface:HasSizeSets 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
heightvalue is null then height is removed.
-
setMinHeight
public void setMinHeight(String value)
Description copied from interface:HasSizeSets 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
minHeightvalue is null then min-height is removed.- Specified by:
setMinHeightin interfaceHasSize- Parameters:
value- the min-height value (ifnull, the property will be removed)
-
setMaxHeight
public void setMaxHeight(String value)
Description copied from interface:HasSizeSets 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
maxHeightvalue is null then max-height is removed.- Specified by:
setMaxHeightin interfaceHasSize- Parameters:
value- the max-height value (ifnull, the property will be removed)
-
getWidth
public String getWidth()
Description copied from interface:HasSizeGets 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
public String getMinWidth()
Description copied from interface:HasSizeGets 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:
getMinWidthin interfaceHasSize- Returns:
- the min-width which has been set for the component
-
getMaxWidth
public String getMaxWidth()
Description copied from interface:HasSizeGets 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:
getMaxWidthin interfaceHasSize- Returns:
- the max-width which has been set for the component
-
getHeight
public String getHeight()
Description copied from interface:HasSizeGets 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
public String getMinHeight()
Description copied from interface:HasSizeGets 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:
getMinHeightin interfaceHasSize- Returns:
- the min-height which has been set for the component
-
getMaxHeight
public String getMaxHeight()
Description copied from interface:HasSizeGets 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:
getMaxHeightin 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:
close()
-
addResizeListener
public Registration addResizeListener(ComponentEventListener<Dialog.DialogResizeEvent> listener)
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
public void add(Component... components)
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:
addin interfaceHasComponents- Parameters:
components- the components to add
-
remove
public void remove(Component... components)
Description copied from interface:HasComponentsRemoves the given child components from this component.- Specified by:
removein interfaceHasComponents- Parameters:
components- the components to remove
-
removeAll
public void removeAll()
Description copied from interface:HasComponentsRemoves all contents from this component, this includes child components, text content as well as child elements that have been added directly to this component using theElementAPI. it also removes the children that were added only at the client-side.- Specified by:
removeAllin interfaceHasComponents
-
addComponentAtIndex
public void addComponentAtIndex(int index, Component component)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:
addComponentAtIndexin 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:
trueif this dialog can be closed with the esc-key,falseotherwise
-
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-trueto enable closing this dialog with the esc-key,falseto 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:
trueif this dialog can be closed by an outside click,falseotherwise
-
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-trueto enable closing this dialog with an outside click,falseto 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-falseto enable dialog to open as modeless modal,trueotherwise.
-
isModal
public boolean isModal()
Gets whether component is set as modal or modeless dialog.- Returns:
trueif modal dialog (default),falseotherwise.
-
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-trueto enable dragging of the dialog,falseotherwise
-
isDraggable
public boolean isDraggable()
Gets whether dialog is enabled to be dragged or not.- Returns:
trueif dragging is enabled,falseotherwise (default).
-
setResizable
public void setResizable(boolean resizable)
Sets whether dialog can be resized by user or not.- Parameters:
resizable-trueto enabled resizing of the dialog,falseotherwise.
-
isResizable
public boolean isResizable()
Gets whether dialog is enabled to be resized or not.- Returns:
trueif resizing is enabled,falsoeotherwiser (default).
-
setHeaderTitle
public void setHeaderTitle(String title)
Sets the title to be rendered on the dialog header.- Parameters:
title- title to be rendered
-
getHeaderTitle
public String getHeaderTitle()
Gets the title set for the dialog header.- Returns:
- the title or an empty string, if a header title is not defined.
-
getHeader
public Dialog.DialogHeader 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
-
getFooter
public Dialog.DialogFooter getFooter()
Gets the object from which components can be added or removed from the dialog footer area. The footer is displayed only if there's 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:
setVisiblein classComponent- Parameters:
visible- dialog visibility- See Also:
Component.setVisible(boolean)
-
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.- Overrides:
setOpenedin classGeneratedVaadinDialog<Dialog>- Parameters:
opened-trueto open the dialog,falseto close it
-
isOpened
public boolean isOpened()
Gets the open state from the dialog.- Returns:
- the
openedproperty from the dialog
-
getChildren
public Stream<Component> getChildren()
Description copied from class:ComponentGets the child components of this component.The default implementation finds child components by traversing each child
Elementtree.If the component is injected to a PolymerTemplate using the
@Idannotation the getChildren method will only return children added from the server side and will not return any children declared in the template file.- Overrides:
getChildrenin classComponent- Returns:
- the child components of this component
- See Also:
Id
-
addOpenedChangeListener
public Registration addOpenedChangeListener(ComponentEventListener<Dialog.OpenedChangeEvent<Dialog>> listener)
Add a lister for event fired by theopened-changedevents.- Overrides:
addOpenedChangeListenerin classGeneratedVaadinDialog<Dialog>- Parameters:
listener- the listener to add- Returns:
- a Registration for removing the event listener
-
addAttachListener
public Registration addAttachListener(ComponentEventListener<AttachEvent> listener)
Adds a attach listener to this component.Note: To listen for opening the dialog, you should use
addOpenedChangeListener(ComponentEventListener).- Specified by:
addAttachListenerin interfaceAttachNotifier- Parameters:
listener- the listener to add, notnull- Returns:
- a handle that can be used for removing the listener
-
addDetachListener
public Registration addDetachListener(ComponentEventListener<DetachEvent> listener)
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:
addDetachListenerin interfaceDetachNotifier- Parameters:
listener- the listener to add, notnull- Returns:
- a handle that can be used for removing the listener
-
addThemeVariants
public void addThemeVariants(DialogVariant... variants)
Adds theme variants to the component.- Parameters:
variants- theme variants to add
-
removeThemeVariants
public void removeThemeVariants(DialogVariant... variants)
Removes theme variants from the component.- Parameters:
variants- theme variants to remove
-
onAttach
protected void onAttach(AttachEvent attachEvent)
Description copied from class:ComponentCalled when the component is attached to a UI.The default implementation does nothing.
This method is invoked before the
AttachEventis fired for the component.
-
getStyle
public Style getStyle()
Description copied from interface:HasStyleGets the style instance for managing inline styles for the element of this component.- Specified by:
getStylein interfaceHasStyle- Returns:
- the style object for the element, not
null - Throws:
UnsupportedOperationException- Dialog does not support adding styles to overlay
-
-