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

Adding support to replace drawer and content within AppLayout. #82

Merged
merged 4 commits into from
Feb 26, 2025

Conversation

vlipovetskii
Copy link
Contributor

@vlipovetskii vlipovetskii commented Feb 12, 2025

Purpose: To have several drawers and contents for AppLayout and switch between them.

For example, navbar contains several tabs.
When a tab is selected, it set its specific drawer and re-populates AppLayout content.
If a tab doesn't have a drawer, removeDrawer() can be called to by its own to clear the previous assigned drawer.

From AppLayout.content the restriction has been removed.
check([email protected] == null) { "The content has already been initialized!" }

@mvysny mvysny merged commit 65066cf into mvysny:master Feb 26, 2025
6 checks passed
@vlipovetskii
Copy link
Contributor Author

@mvysny

@VaadinDsl
public fun (@VaadinDsl Tab).onSelected(handler: OnTabSelectedHandler) : OnTabSelectedHandler {
    val tabs = parent.get() as Tabs
    tabs.onSelectedHandlers[this] = handler
    if (tabs.selectedTab == this) {
        handler()
    }
    return handler
}
    if (tabs.selectedTab == this) {
        handler()
    }

instead of defaultOnSelectedHandler is a brilliant solution!

@vlipovetskii
Copy link
Contributor Author

@mvysny
Please explain, why to leverage provideSingleComponentOrNull in TabSheet.tab and componentColumn and componentColumn instead of provideSingleComponent ? What are the cases covered by returing null instead of component?

@mvysny
Copy link
Owner

mvysny commented Feb 27, 2025

Sure! The ComponentRenderer is free to return null instead of a Component instance; Grid renders an empty cell in such case. This is handy e.g. when the column displays an "edit" button, but the user may not have rights to edit certain rows; for such rows the edit button will be null. In other words, your column looks like this:

componentColumn({
  if (canEdit(it)) {
    button("Edit") { ... }
  }
})

The TabSheet.tab is similar: it's possible to create a tab without the component body; at least I think - if that's not the case, then we should definitely use provideSingleComponent instead.

@vlipovetskii
Copy link
Contributor Author

Now it's clear. Thank you for explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants