Looking up Bootstrap 5 code, I faced this following statement on bootstrap/scss/mixins/_forms.scss
file:
@mixin form-validation-state-selector($state) {
@if ($state == "valid" or $state == "invalid") {
.was-validated #{if(&, "&", "")}:#{$state},
#{if(&, "&", "")}.is-#{$state} {
@content;
}
} @else {
#{if(&, "&", "")}.is-#{$state} {
@content;
}
}
}
And could not exactly understand the usage of &
variable inside the #{if(&, "&", "")}
statements. How is it working?
I know the Ampersand (&
) character is used, os SASS, to include the parent selector(s), when writing on an indented hierarchy. But I couldn't guess how it has been using on the mentioned statement inside the @mixin
, when out of quotes "
.
Can someone explaning it?
Thanks in advance!