Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Notification.getText() #2088

Open
mvysny opened this issue Sep 3, 2021 · 0 comments
Open

Implement Notification.getText() #2088

mvysny opened this issue Sep 3, 2021 · 0 comments
Labels
enhancement New feature or request Impact: Low

Comments

@mvysny
Copy link
Member

mvysny commented Sep 3, 2021

Describe your motivation

Please add Notification.getText(). There's setText() already, so it makes sense to have the getText() function.

Also, I'm trying to create an utility function to add a close button (see vaadin/web-components#438 for details), but I am unable to do so. Adding a component clears the text, so I need to get the text, wrap it in a Span, then add the Span. However, I can't do that since there's no getText().

Describe the solution you'd like

getText() which would return the current text set via setText() or an empty string if the notification has children components.

Describe alternatives you've considered

private val _Notification_templateElement: Field by lazy(LazyThreadSafetyMode.PUBLICATION) {
    val f: Field = Notification::class.java.getDeclaredField("templateElement")
    f.isAccessible = true
    f
}

public val Notification._templateElement: Element
    get() = _Notification_templateElement.get(this) as Element

/**
 * Returns the notification text.
 */
public fun Notification.getText(): String {
    if (isNotEmpty) {
        // adding components to the notification clears the notification text
        return ""
    }
    val e: Element = _templateElement
    return e.getProperty("innerHTML") ?: ""
}

But it doesn't work as well since it will return a <template foo bar text if there are child components.

Additional context

Is there anything else you can add about the proposal?

@web-padawan web-padawan transferred this issue from vaadin/web-components Sep 3, 2021
@yuriy-fix yuriy-fix added enhancement New feature or request Impact: Low labels Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Impact: Low
Projects
None yet
Development

No branches or pull requests

2 participants