rstudio / bslib

Tools for theming Shiny and R Markdown via Bootstrap 3, 4, or 5.
https://rstudio.github.io/bslib/
Other
443 stars 50 forks source link

fix(navbar): Validate `gap` and `padding` early #991

Closed gadenbuie closed 4 months ago

gadenbuie commented 4 months ago

As pointed out in https://github.com/rstudio/bslib/issues/761?notification_referrer_id=NT_kwDOAFK18bI3NDgwODcxMTExOjU0MjA1Mjk#issuecomment-1960464297, page_navbar(padding = 24) isn't handled in the same way as layout_sidebar(padding = 24). In the second case, we pass padding through validateCssPadding(), which resovles 24 to "24px".

In page_navbar(), gap and padding are handed down to many lower-level functions until they're actually used. I think there was an assumption that one of those function would handle the validation.

For the best user experience (finding out early with a reasonable traceback), I've added early validation of these values in page_navbar() and navset_bar(). I also modified validateCssPadding() to return NULL in the base case, which makes it easier to perform the checks and matches validateCssUnit().