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

Fix Quasar's layout rules for ui.card that remove children's borders and shadows #3444

Merged
merged 4 commits into from
Aug 7, 2024

Conversation

falkoschindler
Copy link
Contributor

@falkoschindler falkoschindler commented Aug 6, 2024

Quasar's QCard is the base for ui.card. But in the early days of NiceGUI we decided to set a default gap and padding, so that you don't need to wrap content in card sections. If you do need Quasar's original tight layout, you can call .tight().

But this decision caused quite some trouble, because Quasar keeps removing borders and shadows of child elements, which makes sense for the tight layout without padding, but not with NiceGUI's default card style (#726, #1295, #2265, #2301). We already planned to introduce a new ui.box element to avoid confusion between both behaviors, which would have caused a major breaking change.

Now I finally found a rather neat solution to change Quasar's CSS rules to apply to tight cards only. In my point of view, this is exactly what we needed. I just didn't think of the possibility to manipulate existing rules using JavaScript, which turned out to be pretty easy and powerful.

With this change, the following cards behave as expected:

with ui.card():
    ui.label('Borders and shadows').classes('border shadow')
    ui.label('of child divs').classes('border shadow')
    ui.label('are preserved').classes('border shadow')

with ui.card().tight():
    ui.label('Borders and shadows').classes('border shadow')
    ui.label('of child divs').classes('border shadow')
    ui.label('are removed').classes('border shadow')

Screenshot 2024-08-06 at 10 16 03

Old behavior for reference:

Screenshot 2024-08-06 at 10 16 57

Open tasks:

  • add pytest to avoid regression when updating Quasar
  • update documentation

@falkoschindler falkoschindler added the enhancement New feature or request label Aug 6, 2024
@falkoschindler falkoschindler added this to the 2.0.0 milestone Aug 6, 2024
@falkoschindler falkoschindler linked an issue Aug 6, 2024 that may be closed by this pull request
@falkoschindler falkoschindler changed the base branch from main to 2.0 August 6, 2024 08:56
@falkoschindler falkoschindler marked this pull request as ready for review August 6, 2024 08:56
Copy link
Member

@rodja rodja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a wonderful solution :-)

@rodja rodja merged commit c378456 into 2.0 Aug 7, 2024
7 checks passed
@rodja rodja deleted the card branch August 7, 2024 04:27
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 this pull request may close these issues.

Nesting cards merges the elements
2 participants