FiruzzZ
FiruzzZ

Reputation: 826

Vaadin 14: how to set a notification to close on user interaction?

I am trying to show the users warnings/errors Notifications with duration(0) and I expected the notifications to close when users click on them but nothing happens, there is no way to make these notifications disappear. How it suppose to work when setting the duration to zero? I had this problem almost a year ago, there is an old post in Vaadin's forum but the issues on Github were deleted

old post

Upvotes: 1

Views: 481

Answers (1)

Marcus Hellberg
Marcus Hellberg

Reputation: 1923

You can call notification.close() to close it programmatically.

Button closeButton = new Button("Close");
Notification notification = new Notification(new HorizontalLayout(new Span("Hello!"), closeButton));
notification.setDuration(0);
closeButton.addClickListener(click -> notification.close());
notification.open();

Upvotes: 3

Related Questions