|
| 1 | +--- |
| 2 | +title: Bootstrap 5 migration |
| 3 | +tags: |
| 4 | +- Bootstrap |
| 5 | +--- |
| 6 | + |
| 7 | +<!-- markdownlint-disable no-inline-html --> |
| 8 | + |
| 9 | +import { |
| 10 | + Since, |
| 11 | + ValidExample, |
| 12 | + InvalidExample, |
| 13 | +} from '@site/src/components'; |
| 14 | + |
| 15 | +Bootstrap 5 has evolved with new features, improvements, and changes in its latest version, and along with this some breaking changes also come, which need to be addressed in the migration process. |
| 16 | + |
| 17 | +:::info |
| 18 | + |
| 19 | +See more about Bootstrap 5 breaking changes in the [official documentation](https://getbootstrap.com/docs/5.0/migration/). |
| 20 | + |
| 21 | +::: |
| 22 | + |
| 23 | +To achieve a smoother process and facilitate the moment of the update, the migration has been divided into different steps: |
| 24 | + |
| 25 | +1. **PopperJS upgrade**: This is the first step in the migration process, as Bootstrap 5 requires PopperJS version 2. This step is about upgrading the current PopperJS version to version 2. Because we still need PopperJS version 1 for Bootstrap 4 both versions will co-exist until all usages are migrated to v2. |
| 26 | +2. **SCSS Deprecation process**: A SCSS deprecation process will be needed for the cleanup after BS5 upgrade. More details about it in [SCSS deprecation](../../general/development/policies/deprecation/scss-deprecation). |
| 27 | +3. **Refactoring BS4 features dropped in BS5**: This step is about refactoring the current Bootstrap 4 features that will be deprecated or dropped in its version 5 and they can be replaced with current codebase. |
| 28 | +4. **Create a BS5 "bridge"**: Some simple breaking changes could be also addressed in advance creating a BS5 "bridge". With small additions to this "bridge", we can refactor in advance the occurences in the codebase for some dropped features in BS5. |
| 29 | +5. **BS5 upgrade**: Upgrade the current Bootstrap 4 version to version 5. |
| 30 | +6. **BS4 backwards-compatibility layer**: Alongside the update, a new backwards-compatibility layer will also be created, and some of the Bootstrap 4 syntax will still work until the final deprecation. This will help third-party plugins to be updated in a more gradual way. |
| 31 | +7. **Final deprecation** |
| 32 | + |
| 33 | +:::note |
| 34 | + |
| 35 | +The migration process will be done in a gradual way, and the steps will be executed in different phases. The first phase with the PopperJS upgrade, the SCSS deprecation process and the refactoring will be included in Moodle 4.4. The other steps will be ready in following releases. This documentation page will be updated accordingly with the process. |
| 36 | + |
| 37 | +::: |
| 38 | + |
| 39 | +## Refactoring BS4 features dropped in BS5 |
| 40 | + |
| 41 | +<Since version="4.4" issueNumber="MDL-79914" /> |
| 42 | + |
| 43 | +Some of the Bootstrap 4 classes will be deprecated or dropped in its version 5. To prepare for this, some of the current Bootstrap 4 classes usages have been replaced with version 5 compatible classes. Doing these refactors in advance, will help us to upgrade to Bootstrap 5 in the future. |
| 44 | + |
| 45 | +### Badges |
| 46 | + |
| 47 | +- Badge colour class helpers `.badge-*` have been replaced with background utilities (use `.bg-primary` instead of `.badge-primary`) combined with the corresponding text colour classes (`.text-dark` or `.text-white`) to meet accessibility contrast. |
| 48 | +- The `.badge-pill` class has been replaced with `.rounded-pill` |
| 49 | + |
| 50 | +<InvalidExample title="Don't"> |
| 51 | + |
| 52 | +```html |
| 53 | +<span class="badge badge-danger badge-pill">Error badge</span> |
| 54 | +``` |
| 55 | + |
| 56 | +</InvalidExample> |
| 57 | + |
| 58 | +<ValidExample title="Do"> |
| 59 | + |
| 60 | +```html |
| 61 | +<span class="badge bg-danger text-white rounded-pill">Error badge</span> |
| 62 | +``` |
| 63 | + |
| 64 | +</ValidExample> |
| 65 | + |
| 66 | +### Media |
| 67 | + |
| 68 | +The `.media` component has been replaced with utility classes. |
| 69 | + |
| 70 | +<InvalidExample title="Don't"> |
| 71 | + |
| 72 | +```html |
| 73 | +<div class="media"> |
| 74 | + <div class="media-left"> |
| 75 | + [...] |
| 76 | + </div> |
| 77 | + <div class="media-body"> |
| 78 | + [...] |
| 79 | + </div> |
| 80 | +</div> |
| 81 | +``` |
| 82 | + |
| 83 | +</InvalidExample> |
| 84 | + |
| 85 | +<ValidExample title="Do"> |
| 86 | + |
| 87 | +```html |
| 88 | +<div class="d-flex"> |
| 89 | + <div class="flex-shrink-0"> |
| 90 | + [...] |
| 91 | + </div> |
| 92 | + <div class="flex-grow-1 ml-3"> |
| 93 | + [...] |
| 94 | + </div> |
| 95 | +</div> |
| 96 | +``` |
| 97 | + |
| 98 | +</ValidExample> |
| 99 | + |
| 100 | +### Mixins |
| 101 | + |
| 102 | +The following previously deprecated mixins will be dropped in BS5, so they can be refactored: |
| 103 | + |
| 104 | +- hover, hover-focus, plain-hover-focus and hover-focus-active |
| 105 | +- float-left, float-right and float-none |
| 106 | +- nav-divider |
| 107 | +- img-retina |
| 108 | +- text-hide |
| 109 | +- invisible |
| 110 | +- form-control-focus |
| 111 | +- text-emphasis-variant |
| 112 | +- size |
| 113 | +- make-container-max-widths |
| 114 | +- g-variant and bg-gradient-variant |
| 115 | + |
| 116 | +<InvalidExample title="Don't"> |
| 117 | + |
| 118 | +```css |
| 119 | +.collapse-list-item { |
| 120 | + padding: $collapse-list-item-padding-y $collapse-list-item-padding-x; |
| 121 | + @include hover-focus() { |
| 122 | + background-color: $collapse-list-item-hover-bg; |
| 123 | + border-color: $collapse-list-item-hover-border; |
| 124 | + } |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +</InvalidExample> |
| 129 | + |
| 130 | +<ValidExample title="Do"> |
| 131 | + |
| 132 | +```css |
| 133 | +.collapse-list-item { |
| 134 | + padding: $collapse-list-item-padding-y $collapse-list-item-padding-x; |
| 135 | + &:hover, |
| 136 | + &:focus { |
| 137 | + background-color: $collapse-list-item-hover-bg; |
| 138 | + border-color: $collapse-list-item-hover-border; |
| 139 | + } |
| 140 | +} |
| 141 | +``` |
| 142 | + |
| 143 | +</ValidExample> |
0 commit comments