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

Nesting cards merges the elements #2265

Open
ghbm-itk opened this issue Dec 30, 2023 · 6 comments
Open

Nesting cards merges the elements #2265

ghbm-itk opened this issue Dec 30, 2023 · 6 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@ghbm-itk
Copy link
Contributor

Description

When placing cards inside other cards they merge insted of nesting, which seems very unintentional.

Somehow this also affects toggles. I guess they're based around cards? Or maybe it's the drop shadow that's weird.

If I use intermediate containers like a row the cards don't merge.

from nicegui import ui

ui.toggle(["One", "Two"])

with ui.card():
    ui.toggle(["One", "Two"])

with ui.card():
    with ui.row():
        ui.toggle(["One", "Two"])

with ui.card():
    ui.label("Hello")

with ui.card():
    with ui.card():
        ui.label("Hello")

with ui.card():
    with ui.row():
        with ui.card():
            ui.label("Hello")

ui.run()

2023-12-30 16_41_51-NiceGUI og 3 flere sider - Arbejde - Microsoft​ Edge

It doesn't seems to be a problem in Quasar, but the q-card-sections need to be there for the cards to nest properly:

https://codepen.io/Hermasetas/pen/oNVXKGB

@falkoschindler
Copy link
Contributor

Hi @ghbm-itk, this is an unfortunate consequence of how NiceGUI adds default padding to ui.card, which Quasar doesn't. It has been discussed in #726 and #1295 (comment) and is documented here.

@ghbm-itk
Copy link
Contributor Author

Since the problem is so easily fixed by simply wrapping the element in another element, it seems like something should be possible to fix. I don't understand the backend of NiceGui well enough yet, but I will look into it at some point.

Could a simple hotfix be something like: "If parent is a card wrap this element." ?

@falkoschindler
Copy link
Contributor

@ghbm-itk I don't think it's a good idea to automatically change the element hierarchy, because it would break certain assumptions (see #2040 for a discussion about a similar case).

I tried once again to undo Quasar's CSS magic - without success. But I found a way to wrap the card content in a separate div, so that it isn't affected by the Quasar's CSS; see PR #2301. What do you think?

@falkoschindler falkoschindler self-assigned this Jan 6, 2024
@falkoschindler falkoschindler added the enhancement New feature or request label Jan 6, 2024
@falkoschindler falkoschindler added this to the 2.0.0 milestone Jan 6, 2024
@ghbm-itk
Copy link
Contributor Author

ghbm-itk commented Jan 8, 2024

@falkoschindler Isn't that just q-card-section reinvented? When looking at the examples on quasar.dev it seems that all content in cards is wrapped in card sections:

<q-card>
  <q-card-section>
    <div class="text-h6">Our Changing Planet</div>
    <div class="text-subtitle2">by John Doe</div>
  </q-card-section>
</q-card>

@falkoschindler
Copy link
Contributor

@ghbm-itk Sorry for the late reply. I think it's a bit different:

  • QCards usually don't have any padding. But you can add padding with QCardSections:

    with ui.element('q-card'):
        ui.label('No padding.').classes('border')
    
    with ui.element('q-card'):
        with ui.element('q-card-section'):
            ui.label('Padding.').classes('border')
    Screenshot 2024-02-10 at 23 22 18
  • ui.card comes with padding by default. But in order for Quasar not removing borders of nested elements, adding another container layer helps:

    with ui.card():
        ui.label('Padding.').classes('border')
    
    with ui.card():
        with ui.element():
            ui.label('Padding.').classes('border')
    Screenshot 2024-02-10 at 23 22 56

@falkoschindler
Copy link
Contributor

I just closed PR #2301, because we're no longer convinced that it is a good idea to add additional layers to ui.card to fix a layout inconsistency between NiceGUI and Quasar. Instead, I propose the following:

  1. Change ui.card to mimic QCard more closely. It won't add padding and gaps anymore, and requires to use ui.card_section where padding is required. This is like the old ui.card().tight(). For convenience, we can add QCard's style props as parameters:

    ui.card(*, square: bool = False, flat: bool = False, bordered: bool = False)
  2. Introduce a new ui.box element which behaves like the old ui.card. But instead of using QCard, it is simply a ui.column with optional shadow, border and/or rounded corners. Like the old ui.column and ui.card it adds padding and gaps. Replicating QCard's style props the signature might look like this:

    ui.box(*, square: bool = False, flat: bool = False, bordered: bool = False)

    Or we use more independent and maybe more intuitive parameter names like this:

    ui.box(*, rounded: bool = True, shadow: bool = True, border: bool = False)

Even though this requires all users to change ui.card to ui.box when migrating to NiceGUI 2.0.0, this is a much cleaner solution with less caveats compared to the old ui.card, which almost behaves like QCard, but leads to strange results when nesting bordered elements.

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

Successfully merging a pull request may close this issue.

2 participants