Class Notification
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasComponents,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasTheme,com.vaadin.flow.component.shared.HasThemeVariant<NotificationVariant>,Serializable
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classopened-changedevent is sent when the notification opened state changes.static enumEnumeration of all available positions for notification component -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.Notification(com.vaadin.flow.component.Component... components) Creates a notification with given components inside.Notification(String text) Creates a Notification with the given String rendered as its text, that does not close automatically.Notification(String text, int duration) Creates a Notification with given String rendered as its text and given Integer rendered as its duration.Notification(String text, int duration, Notification.Position position) Creates a Notification with given text String, duration and positionNotification(String text, int duration, Notification.Position position, boolean assertive) Creates a Notification with given text String, duration, position and assertive state. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(Collection<com.vaadin.flow.component.Component> components) Adds the given components into this notification.com.vaadin.flow.shared.RegistrationaddAttachListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.AttachEvent> listener) voidaddComponentAtIndex(int index, com.vaadin.flow.component.Component component) Adds the given component into this notification at the given index.com.vaadin.flow.shared.RegistrationaddDetachListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.DetachEvent> listener) com.vaadin.flow.shared.RegistrationaddOpenedChangeListener(com.vaadin.flow.component.ComponentEventListener<Notification.OpenedChangeEvent> listener) Adds a listener foropened-changedevents fired by the webcomponent.voidclose()Closes the notification.com.vaadin.flow.dom.ClassListintThe duration in milliseconds to show the notification.Description copied from corresponding location in WebComponent:com.vaadin.flow.dom.StylegetStyle()booleanWhen true, the notification card hasaria-liveattribute set toassertiveinstead ofpolite.booleanisOpened()True if the notification is currently displayed.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) protected voidonDetach(com.vaadin.flow.component.DetachEvent detachEvent) voidopen()Opens the notification.voidsetAssertive(boolean assertive) When true, the notification card hasaria-liveattribute set toassertiveinstead ofpolite.voidsetClassName(String className) Sets the CSS class names of the notification overlay element.voidsetDuration(int duration) The duration in milliseconds to show the notification.voidsetOpened(boolean opened) Opens or closes the notification.voidsetPosition(Notification.Position position) Set position of the notification.voidSet the text of the notification with given Stringstatic NotificationShows a notification in the current page with given text.static Notificationshow(String text, int duration, Notification.Position position) Shows a notification in the current page with given text, duration and position.static Notificationshow(String text, int duration, Notification.Position position, boolean assertive) Shows a notification in the current page with given text, duration, position and assertive state.Methods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.HasComponents
add, add, addComponentAsFirst, remove, remove, removeAllMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, hasClassName, removeClassName, removeClassNames, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, bindThemeName, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariants
-
Constructor Details
-
Notification
public Notification()Default constructor. Create an empty notification with component support and non-auto-closingNote: To mix text and child components in notification that also supports child components, use the
Textcomponent for the textual parts. -
Notification
Creates a Notification with the given String rendered as its text, that does not close automatically.- Parameters:
text- the text of the Notification
-
Notification
Creates a Notification with given String rendered as its text and given Integer rendered as its duration.Set to
0or a negative number to disable the notification auto-closing.- Parameters:
text- the text of the Notificationduration- the duration in milliseconds to show the notification
-
Notification
Creates a Notification with given text String, duration and positionSet to
0or a negative number to disable the notification auto-closing.- Parameters:
text- the text of the notificationduration- the duration in milliseconds to show the notificationposition- the position of the notification. Valid enumerate values are TOP_STRETCH, TOP_START, TOP_CENTER, TOP_END, MIDDLE, BOTTOM_START, BOTTOM_CENTER, BOTTOM_END, BOTTOM_STRETCH
-
Notification
Creates a Notification with given text String, duration, position and assertive state.Set to
0or a negative number to disable the notification auto-closing.- Parameters:
text- the text of the notificationduration- the duration in milliseconds to show the notificationposition- the position of the notification. Valid enumerate values are TOP_STRETCH, TOP_START, TOP_CENTER, TOP_END, MIDDLE, BOTTOM_START, BOTTOM_CENTER, BOTTOM_END, BOTTOM_STRETCHassertive- whether the notification should havearia-liveattribute set toassertiveorpolite
-
Notification
public Notification(com.vaadin.flow.component.Component... components) Creates a notification with given components inside.Note: To mix text and child components in a component that also supports child components, use the
Textcomponent for the textual parts.- Parameters:
components- the components inside the notification- See Also:
-
-
Method Details
-
show
public static Notification show(String text, int duration, Notification.Position position, boolean assertive) Shows a notification in the current page with given text, duration, position and assertive state.This automatically adds the notification to the
UI, and automatically removes it from the UI when it closes. Note that the notification is then scoped to the UI, and not the current view. As such, when navigating away from a view, the notification will still be opened or stay open. In order to close the notification when navigating away from a view, it should either be explicitly added as a child to the view, or it should be explicitly closed when leaving the view.- Parameters:
text- the text of the Notificationduration- the duration in milliseconds to show the notificationposition- the position of the notification. Valid enumerate values are TOP_STRETCH, TOP_START, TOP_CENTER, TOP_END, MIDDLE, BOTTOM_START, BOTTOM_CENTER, BOTTOM_END, BOTTOM_STRETCHassertive- whether the notification should havearia-liveattribute set toassertiveorpolite- Returns:
- the notification
-
show
Shows a notification in the current page with given text, duration and position.This automatically adds the notification to the
UI, and automatically removes it from the UI when it closes. Note that the notification is then scoped to the UI, and not the current view. As such, when navigating away from a view, the notification will still be opened or stay open. In order to close the notification when navigating away from a view, it should either be explicitly added as a child to the view, or it should be explicitly closed when leaving the view.- Parameters:
text- the text of the Notificationduration- the duration in milliseconds to show the notificationposition- the position of the notification. Valid enumerate values are TOP_STRETCH, TOP_START, TOP_CENTER, TOP_END, MIDDLE, BOTTOM_START, BOTTOM_CENTER, BOTTOM_END, BOTTOM_STRETCH- Returns:
- the notification
-
show
Shows a notification in the current page with given text.This is the convenience method for
show(String, int, Position)which uses default web-component values for duration (which is 5000 ms) and position (Position.BOTTOM_START).This automatically adds the notification to the
UI, and automatically removes it from the UI when it closes. Note that the notification is then scoped to the UI, and not the current view. As such, when navigating away from a view, the notification will still be opened or stay open. In order to close the notification when navigating away from a view, it should either be explicitly added as a child to the view, or it should be explicitly closed when leaving the view.- Parameters:
text- the text of the Notification- Returns:
- the notification
-
setText
Set the text of the notification with given StringNOTE: When mixing this method with
Notification()andNotification(Component...). Method will remove all the components from the notification.- Parameters:
text- the text of the Notification
-
setPosition
Set position of the notification.- Parameters:
position- the position of the notification. Valid enumerate values areTOP_STRETCH, TOP_START, TOP_CENTER, TOP_END, MIDDLE, BOTTOM_START, BOTTOM_CENTER, BOTTOM_END, BOTTOM_STRETCH, notnull
-
getPosition
Description copied from corresponding location in WebComponent:
Alignment of the notification in the viewport Valid values are
top-stretch|top-start|top-center|top-end|middle|bottom-start|bottom-center|bottom-end|bottom-stretchThis property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
The default position value is Position.BOTTOM_START.
- Returns:
- the
Notification.Positionproperty from the webcomponent
-
open
public void open()Opens the notification. -
close
public void close()Closes the notification.This automatically removes the notification from the
UI, unless it was manually added to a parent component. -
add
Adds the given components into this notification.The elements in the DOM will not be children of the
<vaadin-notification>element, but will be inserted into an overlay that is attached into the<body>.NOTE: When mixing this method with
Notification(String),Notification(String, int)andNotification(String, int, Position)method will remove the text content.- Specified by:
addin interfacecom.vaadin.flow.component.HasComponents- Parameters:
components- the components to add
-
addComponentAtIndex
public void addComponentAtIndex(int index, com.vaadin.flow.component.Component component) Adds the given component into this notification at the given index.The element in the DOM will not be child of the
<vaadin-notification>element, but will be inserted into an overlay that is attached into the<body>.NOTE: When mixing this method with
Notification(String),Notification(String, int)andNotification(String, int, Position)method will remove the text content.- Specified by:
addComponentAtIndexin interfacecom.vaadin.flow.component.HasComponents- Parameters:
index- the index, where the component will be added.component- the component to add
-
setOpened
public void setOpened(boolean opened) Opens or closes the notification.If a notification was not added manually to a parent component, it will be automatically added to the
UIwhen opened, and automatically removed from the UI when closed. Note that the notification is then scoped to the UI, and not the current view. As such, when navigating away from a view, the notification will still be opened or stay open. In order to close the notification when navigating away from a view, it should either be explicitly added as a child to the view, or it should be explicitly closed when leaving the view.- Parameters:
opened-trueto open the notification,falseto close it
-
isOpened
@Synchronize(property="opened", value="opened-changed", allowInert=true) public boolean isOpened()True if the notification is currently displayed.This property is synchronized automatically from client side when an
opened-changedevent happens.- Returns:
- the
openedproperty from the webcomponent
-
addOpenedChangeListener
public com.vaadin.flow.shared.Registration addOpenedChangeListener(com.vaadin.flow.component.ComponentEventListener<Notification.OpenedChangeEvent> listener) Adds a listener foropened-changedevents fired by the webcomponent.- Parameters:
listener- the listener- Returns:
- a
Registrationfor removing the event listener
-
setDuration
public void setDuration(int duration) The duration in milliseconds to show the notification. Set to0or a negative number to disable the notification auto-closing.- Parameters:
duration- the value to set
-
getDuration
public int getDuration()The duration in milliseconds to show the notification. Set to
0or a negative number to disable the notification auto-closing.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
durationproperty from the webcomponent
-
setAssertive
public void setAssertive(boolean assertive) When true, the notification card hasaria-liveattribute set toassertiveinstead ofpolite. This makes screen readers announce the notification content immediately when it appears.- Parameters:
assertive- the value to set
-
isAssertive
public boolean isAssertive()When true, the notification card hasaria-liveattribute set toassertiveinstead ofpolite. This makes screen readers announce the notification content immediately when it appears.- Returns:
- the
assertiveproperty from the webcomponent
-
addAttachListener
public com.vaadin.flow.shared.Registration addAttachListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.AttachEvent> listener) Note: To listen for opening the notification, you should use
addOpenedChangeListener(ComponentEventListener).- Specified by:
addAttachListenerin interfacecom.vaadin.flow.component.AttachNotifier
-
addDetachListener
public com.vaadin.flow.shared.Registration addDetachListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.DetachEvent> listener) Note: To listen for closing the notification, you should use
addOpenedChangeListener(ComponentEventListener), as the component is not necessarily removed from the DOM when closing.- Specified by:
addDetachListenerin interfacecom.vaadin.flow.component.DetachNotifier
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
onDetach
protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent) - Overrides:
onDetachin classcom.vaadin.flow.component.Component
-
setClassName
Sets the CSS class names of the notification overlay element. This method overwrites any previous set class names.- Specified by:
setClassNamein interfacecom.vaadin.flow.component.HasStyle- Parameters:
className- a space-separated string of class names to set, ornullto remove all class names
-
getClassNames
public com.vaadin.flow.dom.ClassList getClassNames()- Specified by:
getClassNamesin interfacecom.vaadin.flow.component.HasStyle
-
getStyle
public com.vaadin.flow.dom.Style getStyle()- Specified by:
getStylein interfacecom.vaadin.flow.component.HasStyle- Throws:
UnsupportedOperationException- Notification does not support adding styles to card element
-