rstudio / bslib

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

Add an `inline` option to input_switch() #1128

Open dvg-p4 opened 4 weeks ago

dvg-p4 commented 4 weeks ago

I'd like to make a switch input that has labels on both the left and right sides. The most straightforward way I can think of to try to do this would be to put some manual spans on the left or right on the same line. But the switch input is wrapped in a div, which makes it always appear on its own line.

It looks from the source code like the internal function actually has an inline parameter, so I suggest just exposing it in input_switch() (unless there's a reason that'd break things):

https://github.com/rstudio/bslib/blob/85b042832e1520b5f06dc95c769396816be76eca/R/input-switch.R#L83C100-L83C114

dvg-p4 commented 4 weeks ago

(Any other suggested workarounds would also be appreciated)

dvg-p4 commented 4 weeks ago

Hmm, I might be doing a bit of "XY" problem here on second thought, it would probably be better to just have a version of the switch that includes a label on the left. Although it seems like that's not an out-of-the-box bootstrap option, and you've got to be a bit hacky with margins, as in https://www.codeply.com/p/BIXQkD77C4

dvg-p4 commented 4 weeks ago

Although on third thought, inline switches can be useful in their own right, and are supported natively in bootstrap with form-check-inline (this seems to work for switches, even though it's not explicitly documented: https://www.codeply.com/p/WEjnvgV7yG)