Closed jasonfb closed 1 year ago
I can see based on tutorials on the internet and also based on the wrong answers on this SO post https://stackoverflow.com/questions/71216446/bootstrap-5-1-not-working-in-jsbundling-rails-7
that perhaps this was working once about a year ago? I have been testing against Rails 7.0.4
I also tested against Rails 7.0.0 and got the same result. I do not see why others seem to get a different result here,I tried this on two separate machines using Ruby 3.1.3 and Node 16.17.1
is the problem here that the JS part of Boostrap just doesn't work with ESBUILD?
If I add back importmaps and then PIN the Bootstrap dependencies, it works.
Can't replicate when using Bootstrap 5.0 example code from here: https://getbootstrap.com/docs/5.0/components/navbar/
Works out of the box with rails new app --css bootstrap -j rebuild
.
Looks like the problem is that your HTML contains data attributes not recognized by Bootstrap 5.0. You have:
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
You need:
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
Confirmed--- I was using the example navbar code from Bootstrap 4. My mistake. Thank you @dhh
Steps to reproduce:
rails new Xyz --css=bootstrap --js=esbuild
generate default controller
to
app/views/welcome/index.erb
add this basic Navbar:Boot the app with
./bin/dev
result: Javascript interactions do not work![bootstrap-no-js](https://user-images.githubusercontent.com/59002/210205885-a640b3fb-aef8-4ee7-a515-9f7b0a41d160.gif)
expected result: When I click on the drop-down, the submenu is exposed (JS interactions work)![bootstrap-workingjs](https://user-images.githubusercontent.com/59002/210206050-242343a1-7ad7-493a-8433-cc63ce0599ba.gif)
Sample app (broken, following steps above): https://github.com/jasonfb/BootstrapTest2
TO BUILD A CORRECTLY WORKING BOOTSTRAP APP STARTING WITH ESBUILD, FOLLOW THESE INSTRUCTIONS
rails new HelloWorld --javascript=esbuild
then adding
bundle add "sassc-rails"
addcss: yarn build:css --watch
to Procfile.devyarn add @popperjs/core bootstrap bootstrap-icons sass
In package.json, add to the “scripts” section the bold line:IN APP/ASSETS/CONFIG/MANIFEST.JS, REMOVE THIS LINE:
DELETE THE FILE AT APP/ASSETS/STYLESHEETS/APPLICATION.CSS AND REPLACE IT WITH A FILE APP/ASSETS/STYLESHEETS/APPLICATION.SCSS
THEN TO APP/JAVASCRIPT/APPLICATION.JS (YOUR ESBUILD PACK FILE), ADD:
TO CONFIG/INITIALIZERS/ASSETS.RB, ADD THIS LINE:
Sample app (working): https://github.com/jasonfb/BootstrapTest3
What is strange to me is that examining my two apps (BootstrapTest2 and BootstrapTest3) I can't see what the difference is why it is working in BootstrapTest3 and not BootstrapTest2