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

Bootstrap 5 updates #329

Merged
merged 50 commits into from May 21, 2021
Merged

Bootstrap 5 updates #329

merged 50 commits into from May 21, 2021

Conversation

mhw
Copy link
Contributor

@mhw mhw commented Apr 6, 2021

I wanted to get Simple Form working with Bootstrap 5 for a new application I'm working on. To make sure I did a complete job I've updated the example application as it seems to cover most of the form variants. This PR contains the updates I've made to get things working.

I'm not sure how you might want to handle the release of Bootstrap 5: while I'm sure there'll be some demand for Simple Form being updated when Bootstrap 5 ships, I imagine continued support for Bootstrap 4 will be needed for a while too. As the Bootstrap assets are pulled in to this app as a gem dependency it would be tricky to support both versions from one instance of the app. Perhaps a second instance of the app could be deployed, but that might mean keeping the master and bootstrap-5 branches separate.

Similarly, when adding this to the simple_form gem it might be worth keeping the generator for Bootstrap 4, at least for a while.

Key points:

  • Bootstrap 5 drops the .custom-* styles as they've been largely merged into the .form-* ones. I've dropped the custom form sample and the chunk of the initializer that implements it.

  • Floating label support is now built in, so I've converted the example to use the Bootstrap 5 classes and removed _form_floating_labels.scss. Selects with multiple aren't supported though, so I've removed that from the example.

  • Input groups with validation feedback need a .has-validation class and the feedback pulled inside the input group. This works fine for the Simple Form generated markup as it will only create a single .invalid-feedback element. The HTML in app/views/examples/input_groups/_bootstrap.html.erb has both .invalid-feedback and .valid-feedback elements, and loses the rounded end on the input group - see Fix input group border radii twbs/bootstrap#31953 and Missing border radius on input group with validation feedback twbs/bootstrap#25110 (comment).

Still to do:

  • Review and update the documentation pages

Fixes #323

mhw added 30 commits April 3, 2021 23:22
They aren't used by bootstrap and .form-group has gone in v5
as well.
Also add :vertical_select wrapper for `<select>` lists used for
associations. Without this, the select elements would use the
default :vertical_form wrapper and get the .form-control class.
When a boolean is rendered as radio buttons a hidden `<input>`
element is added between the `<legend>` and first `<div>`
wrapping a radio button. Bootstrap's styling floats the legend
left and needs the following element to be cleared, but this
does not work if the following element is not displayed. We add
an additional rule to target the first following wrapper `<div>`.
.active has gone; check for .btn so we only process events
from the input elements, not the labels.

Don't preventDefault() on the event, so the radio button will
toggle.
As for horizontals, add :horizontal_select wrapper for `<select>`
lists used for associations. Without this, the select elements
would use the default :horizontal_form wrapper and get the
.form-control class.
mhw added 12 commits April 6, 2021 22:04
Needs updating as .input-group-append wrapper div isn't used
any more.
Not supported by Bootstrap 5's floating labels implementation.
New .has-validation class was added so validation feedback can move
inside input-group. This works ok for simple_form, but the plain
HTML version with both .valid-feedback and .invalid-feedback divs
loses the rounded end on the input group.

See twbs/bootstrap#25110
@m5o
Copy link
Collaborator

m5o commented Apr 9, 2021

Hey 👋 @mhw Thank you for the awesome work!! Let me think about the process and structure and if it’s really necessary to maintain two instances (may just for a fixed time).
Will inspect & review your PR in a few days, busy atm.

@m5o
Copy link
Collaborator

m5o commented May 12, 2021

So, in the meantime Bootstrap released the final v5 🎉

@mhw - Could you check/verify if your PR includes possible last minute tweaks.
(Did not follow all the little changes between v4/v5-beta this time)

@mhw
Copy link
Contributor Author

mhw commented May 12, 2021

Yep, good idea. Give me a day or so and I'll check if anything needs tweaking.

@mhw
Copy link
Contributor Author

mhw commented May 14, 2021

I've reviewed the diff between 5.0.0.beta2 and 5.0.0 and there are no changes to the form styling that need any tweaks. I've bumped the dependency and synced application.scss with the file in bootstrap-rubygem.

I'll have a look at the documentation and see what needs updating there.

Copy link
Collaborator

@m5o m5o left a comment

Choose a reason for hiding this comment

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

✨ 10x Thank you @mhw 🥳

@m5o m5o merged commit 8038169 into heartcombo:master May 21, 2021
@m5o
Copy link
Collaborator

m5o commented May 21, 2021

@mhw Because all kudos go to you 🙇‍♂️

Would you like to create the official PR to heartcombo/simple_form?

It's basically just the update of config/initializers/simple_form_bootstrap.rb
As I know from @carlosantoniodasilva, there is no plan to support multiple bootstrap generator versions side-by-side.

@mhw
Copy link
Contributor Author

mhw commented May 21, 2021

Sure, I'll take a swing at that. Thanks!

@carlosantoniodasilva
Copy link
Member

Thanks for the work @mhw and @m5o!

Yes, I think it's easier for SF if we just keep the most recent version of the initializer there, and point people via readme/docs/generator install readme to the v4 generator on the app here if that's what they need. (I'm assuming that most people setting up SF + Bootstrap would do on a new app and are likely going with v5 in that case.)

@olimart
Copy link

olimart commented May 23, 2021

Thanks a lot @mhw 🙏

@m5o
Copy link
Collaborator

m5o commented May 29, 2021

🔗 heartcombo/simple_form#1738

woto added a commit to woto/hub that referenced this pull request Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

bootstrap 5 dropped .form-group
4 participants