Class Notification
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasComponents,HasElement,HasEnabled,HasStyle,HasTheme,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(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<Component> components) Adds the given components into this notification.addAttachListener(ComponentEventListener<AttachEvent> listener) Adds a attach listener to this component.voidaddComponentAtIndex(int index, Component component) Adds the given component into this notification at the given index.addDetachListener(ComponentEventListener<DetachEvent> listener) Adds a detach listener to this component.Adds a listener foropened-changedevents fired by the webcomponent.voidclose()Closes the notification.Gets the set of CSS class names used for this element.intThe duration in milliseconds to show the notification.Description copied from corresponding location in WebComponent:getStyle()Gets the style instance for managing inline styles for the element of this component.booleanWhen true, the notification card hasaria-liveattribute set toassertiveinstead ofpolite.booleanisOpened()True if the notification is currently displayed.protected voidonAttach(AttachEvent attachEvent) Called when the component is attached to a UI.protected voidonDetach(DetachEvent detachEvent) Called when the component is detached from a UI.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, 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
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, 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
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 interfaceHasComponents- Parameters:
components- the components to add
-
addComponentAtIndex
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 interfaceHasComponents- 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
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 Registration addOpenedChangeListener(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
Adds a attach listener to this component.Note: To listen for opening the notification, 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
Adds a detach listener to this component.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 interfaceDetachNotifier- Parameters:
listener- the listener to add, notnull- Returns:
- a handle that can be used for removing the listener
-
onAttach
Description copied from class:ComponentCalled when the component is attached to a UI.This method is invoked before the
Make sure to callAttachEventis fired for the component.super.onAttachwhen overriding this method. -
onDetach
Description copied from class:ComponentCalled when the component is detached from a UI.This method is invoked before the
DetachEventis fired for the component.Make sure to call
super.onDetachwhen overriding this method. -
setClassName
Sets the CSS class names of the notification overlay element. This method overwrites any previous set class names.- Specified by:
setClassNamein interfaceHasStyle- Parameters:
className- a space-separated string of class names to set, ornullto remove all class names
-
getClassNames
Description copied from interface:HasStyleGets 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 theclassattribute.Despite the name implying a list being returned, the return type is actually a
Setsince the in-browser return value behaves like aSetin Java.- Specified by:
getClassNamesin interfaceHasStyle- Returns:
- a list of class names, never
null - See Also:
-
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- Notification does not support adding styles to card element
-