Skip to content

Commit c8868f4

Browse files
roland04ferranrecio
authored andcommitted
[docs] Devdocs Bootstrap 5 upgrade
1 parent 556a2df commit c8868f4

File tree

1 file changed

+198
-0
lines changed

1 file changed

+198
-0
lines changed

docs/guides/bs5migration/index.md

+198
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,201 @@ The `.font-italic` class has been replaced with `.fst-italic` for brevity and co
472472
```
473473

474474
</ValidExample>
475+
476+
## Bootstrap 5 upgrade
477+
478+
<Since version="5.0" issueNumber="MDL-75669" />
479+
480+
After **Refactoring BS4 features dropped in BS5** and **Create a BS5 "bridge"**, the remaining Bootstrap breaking changes will be addressed in the upgrade to Bootstrap 5.
481+
482+
The `bs5-bridge.scss` SCSS file will be removed as it will no longer be needed, and the Bootstrap library in theme_boost will be upgraded to version 5.3. After that the codebase will be fully compatible with Bootstrap 5.
483+
484+
### Refactor dropdowns positioning classes
485+
486+
Replace `.dropdown-menu-[left|right]` with `.dropdown-menu-[start|end]`.
487+
488+
<InvalidExample title="Don't">
489+
490+
```html
491+
<div class="dropdown-menu dropdown-menu-right">
492+
[...]
493+
</div>
494+
```
495+
496+
</InvalidExample>
497+
498+
<ValidExample title="Do">
499+
500+
```html
501+
<div class="dropdown-menu dropdown-menu-end">
502+
[...]
503+
</div>
504+
```
505+
506+
</ValidExample>
507+
508+
### Refactor custom form elements
509+
510+
- `.custom-check` is now `.form-check`.
511+
- `.custom-check.custom-switch` is now `.form-check.form-switch`.
512+
- `.custom-select` is now `.form-select`.
513+
- `.custom-file` and `.form-file` have been replaced by custom styles on top of `.form-control`.
514+
- `.custom-range` is now `.form-range`.
515+
- Dropped `.input-group-append` and `.input-group-prepend`. You can now just add buttons and `.input-group-text` as direct children of the input groups.
516+
517+
<InvalidExample title="Don't">
518+
519+
```html
520+
<select name="outcome" class="custom-select"> [...] </select>
521+
522+
<div class="input-group">
523+
<input type="text" class="form-control"> [...] </input>
524+
<div class="input-group-append">
525+
<button type="submit" class="btn btn-primary search-icon">
526+
{{#pix}} a/search, core {{/pix}}
527+
<span class="visually-hidden">{{#str}} search, core {{/str}}</span>
528+
</button>
529+
</div>
530+
</div>
531+
```
532+
533+
</InvalidExample>
534+
535+
<ValidExample title="Do">
536+
537+
```html
538+
<select name="outcome" class="form-select"> [...] </select>
539+
540+
<div class="input-group">
541+
<input type="text" class="form-control"> [...] </input>
542+
<button type="submit" class="btn btn-primary search-icon">
543+
{{#pix}} a/search, core {{/pix}}
544+
<span class="visually-hidden">{{#str}} search, core {{/str}}</span>
545+
</button>
546+
</div>
547+
```
548+
549+
</ValidExample>
550+
551+
### Refactor media query mixins
552+
553+
- `media-breakpoint-down()` uses the breakpoint itself instead of the next breakpoint (e.g., `media-breakpoint-down(lg)` instead of `media-breakpoint-down(md)` targets viewports smaller than lg).
554+
- In `media-breakpoint-between()` the second parameter also uses the breakpoint itself instead of the next breakpoint (e.g., `media-breakpoint-between(sm, lg)` instead of `media-breakpoint-between(sm, md)` targets viewports between sm and lg).
555+
556+
<InvalidExample title="Don't">
557+
558+
```css
559+
// This will target viewports smaller than md.
560+
@include media-breakpoint-down(sm) {
561+
[...]
562+
}
563+
```
564+
565+
</InvalidExample>
566+
567+
<ValidExample title="Do">
568+
569+
```css
570+
// This will target viewports smaller than md.
571+
@include media-breakpoint-down(md) {
572+
[...]
573+
}
574+
```
575+
576+
</ValidExample>
577+
578+
### Refactor BS5 data attributes
579+
580+
Data attributes for all JavaScript plugins are now namespaced to help distinguish Bootstrap functionality from our own code.
581+
582+
<InvalidExample title="Don't">
583+
584+
```html
585+
// Tooltip.
586+
<button class="btn btn-outline-secondary"
587+
type="button"
588+
data-toggle="tooltip"
589+
data-html="true"
590+
title="{{#str}} string_with_html, block_my_block {{/str}}"
591+
>
592+
{{#pix}} i/info, core {{/pix}}
593+
</button>
594+
595+
// Collapse.
596+
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapsableContent" aria-expanded="false" aria-controls="collapseExample">
597+
Open the collapsable content
598+
</button>
599+
<div class="collapse" id="collapsableContent">
600+
[...]
601+
</div>
602+
```
603+
604+
</InvalidExample>
605+
606+
<ValidExample title="Do">
607+
608+
```html
609+
// Tooltip.
610+
<button class="btn btn-outline-secondary"
611+
type="button"
612+
data-bs-toggle="tooltip"
613+
data-bs-html="true"
614+
title="{{#str}} string_with_html, block_my_block {{/str}}"
615+
>
616+
{{#pix}} i/info, core {{/pix}}
617+
</button>
618+
619+
// Collapse.
620+
<button class="btn btn-primary"
621+
type="button"
622+
data-bs-toggle="collapse"
623+
data-bs-target="#collapsableContent"
624+
aria-expanded="false"
625+
aria-controls="collapseExample"
626+
>
627+
Open the collapsable content
628+
</button>
629+
<div class="collapse" id="collapsableContent">
630+
[...]
631+
</div>
632+
```
633+
634+
</ValidExample>
635+
636+
### Bootstrap 5 and Jquery
637+
638+
Bootstrap dropped jQuery dependency and rewrote plugins to be in regular JavaScript. This means that all the jQuery Bootstrap-related code in the Moodle codebase has been rewritten in vanilla JavaScript.
639+
640+
<InvalidExample title="Don't">
641+
642+
```js
643+
import $ from 'jquery';
644+
645+
$(document).on('shown shown.bs.tab', function(e) {
646+
[...]
647+
$('#my-dropdown').dropdown('toggle');
648+
});
649+
```
650+
651+
</InvalidExample>
652+
653+
<ValidExample title="Do">
654+
655+
```js
656+
import Dropdown from 'theme_boost/bootstrap/dropdown';
657+
document.querySelectorAll('[data-bs-toggle="tab"]').forEach((tab) => {
658+
tab.addEventListener('shown.bs.tab', (e) => {
659+
[...]
660+
const bootstrapDropdown = new Dropdown('#my-dropdown');
661+
bootstrapDropdown.toggle();
662+
});
663+
});
664+
```
665+
666+
</ValidExample>
667+
668+
:::info backwards compatibility
669+
670+
Although Bootstrap does not need jQuery anymore, it is still possible to use it in Moodle. See MDL-84324 for more information.
671+
672+
:::

0 commit comments

Comments
 (0)