Skip to content

Commit a9d8949

Browse files
mhrabieetkrotoff
authored andcommitted
RTL support
Add RTL mode to support languages like Persian, Arabic, Hebrew... using HTML's dir attribute
1 parent f9be09d commit a9d8949

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

example/index.html

+18
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,24 @@ <h2>
295295
</div>
296296
</div>
297297
</div>
298+
299+
<h2>Support for "right to left" languages</h2>
300+
<bdo dir="rtl">
301+
<div class="form-group floating-label">
302+
<input id="input-rtl" class="form-control" placeholder="input RTL" />
303+
<label for="input-rtl">input RTL</label>
304+
</div>
305+
<div class="form-group floating-label">
306+
<select class="form-control" id="select-rtl">
307+
<option>1</option>
308+
<option>2</option>
309+
<option>3</option>
310+
<option>4</option>
311+
<option>5</option>
312+
</select>
313+
<label for="select-rtl">select RTL</label>
314+
</div>
315+
</bdo>
298316
</div>
299317

300318
<script src="./index.tsx"></script>

src/bootstrap4-floating-label.scss

+16
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ $label-top-position-lg: #{- $label-height-lg + $label-height-lg / 2.5}; // -30px
6666
@include text-truncate;
6767
}
6868

69+
// Support for "right to left" languages
70+
[dir='rtl'] {
71+
%label-inside-input-rtl {
72+
left: auto !important;
73+
right: 0;
74+
}
75+
%label-above-input-rtl {
76+
left: auto !important;
77+
right: $input-padding-x-sm;
78+
}
79+
}
80+
6981
@mixin label-inside-input-common {
7082
@include label-common;
7183

@@ -76,6 +88,8 @@ $label-top-position-lg: #{- $label-height-lg + $label-height-lg / 2.5}; // -30px
7688
// see https://github.com/mui-org/material-ui/blob/v3.3.2/packages/material-ui/src/NativeSelect/NativeSelect.js#L77
7789
// See ["the mouse event go "through" the element and target whatever is "underneath" that element instead"](https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events)
7890
pointer-events: none;
91+
92+
@extend %label-inside-input-rtl;
7993
}
8094

8195
@mixin label-inside-input-sm {
@@ -118,6 +132,8 @@ $transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
118132

119133
// Visible when the label is above an input with a different background color
120134
border-radius: $border-radius;
135+
136+
@extend %label-above-input-rtl;
121137
}
122138

123139
// If a browser does not support a CSS pseudo-element, we cannot group/merge it with other CSS pseudo-elements:

0 commit comments

Comments
 (0)