aboutsummaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
authorGaĆ«l Poupard <[email protected]>2020-06-26 17:06:20 +0300
committerXhmikosR <[email protected]>2020-12-04 07:52:03 +0200
commit9488978fb55286ba83e8193a871d1ff9815045b9 (patch)
treeabb461d46722f107e54156709c88cf37ed9e24a6 /js/src
parent71ecc3323fb60ea05456470d10d17b614fe6dc04 (diff)
downloadbootstrap-9488978fb55286ba83e8193a871d1ff9815045b9.tar.xz
bootstrap-9488978fb55286ba83e8193a871d1ff9815045b9.zip
feat(RTL): implement RTL
Using RTLCSS directives, renaming things to use logical names and following best practices.
Diffstat (limited to 'js/src')
-rw-r--r--js/src/carousel.js8
-rw-r--r--js/src/dropdown.js27
-rw-r--r--js/src/modal.js5
-rw-r--r--js/src/popover.js2
-rw-r--r--js/src/tooltip.js19
-rw-r--r--js/src/util/index.js5
6 files changed, 42 insertions, 24 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js
index 9c6fb53ee..d8ad3a135 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -79,8 +79,8 @@ const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
const CLASS_NAME_CAROUSEL = 'carousel'
const CLASS_NAME_ACTIVE = 'active'
const CLASS_NAME_SLIDE = 'slide'
-const CLASS_NAME_RIGHT = 'carousel-item-right'
-const CLASS_NAME_LEFT = 'carousel-item-left'
+const CLASS_NAME_END = 'carousel-item-end'
+const CLASS_NAME_START = 'carousel-item-start'
const CLASS_NAME_NEXT = 'carousel-item-next'
const CLASS_NAME_PREV = 'carousel-item-prev'
const CLASS_NAME_POINTER_EVENT = 'pointer-event'
@@ -442,11 +442,11 @@ class Carousel extends BaseComponent {
let eventDirectionName
if (direction === DIRECTION_NEXT) {
- directionalClassName = CLASS_NAME_LEFT
+ directionalClassName = CLASS_NAME_START
orderClassName = CLASS_NAME_NEXT
eventDirectionName = DIRECTION_LEFT
} else {
- directionalClassName = CLASS_NAME_RIGHT
+ directionalClassName = CLASS_NAME_END
orderClassName = CLASS_NAME_PREV
eventDirectionName = DIRECTION_RIGHT
}
diff --git a/js/src/dropdown.js b/js/src/dropdown.js
index 7b3bf5b4e..0ac108ab8 100644
--- a/js/src/dropdown.js
+++ b/js/src/dropdown.js
@@ -11,6 +11,7 @@ import {
getElementFromSelector,
isElement,
isVisible,
+ isRTL,
noop,
typeCheckConfig
} from './util/index'
@@ -53,9 +54,9 @@ const EVENT_KEYUP_DATA_API = `keyup${EVENT_KEY}${DATA_API_KEY}`
const CLASS_NAME_DISABLED = 'disabled'
const CLASS_NAME_SHOW = 'show'
const CLASS_NAME_DROPUP = 'dropup'
-const CLASS_NAME_DROPRIGHT = 'dropright'
-const CLASS_NAME_DROPLEFT = 'dropleft'
-const CLASS_NAME_MENURIGHT = 'dropdown-menu-right'
+const CLASS_NAME_DROPEND = 'dropend'
+const CLASS_NAME_DROPSTART = 'dropstart'
+const CLASS_NAME_MENUEND = 'dropdown-menu-end'
const CLASS_NAME_NAVBAR = 'navbar'
const CLASS_NAME_POSITION_STATIC = 'position-static'
@@ -65,12 +66,12 @@ const SELECTOR_MENU = '.dropdown-menu'
const SELECTOR_NAVBAR_NAV = '.navbar-nav'
const SELECTOR_VISIBLE_ITEMS = '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)'
-const PLACEMENT_TOP = 'top-start'
-const PLACEMENT_TOPEND = 'top-end'
-const PLACEMENT_BOTTOM = 'bottom-start'
-const PLACEMENT_BOTTOMEND = 'bottom-end'
-const PLACEMENT_RIGHT = 'right-start'
-const PLACEMENT_LEFT = 'left-start'
+const PLACEMENT_TOP = isRTL ? 'top-end' : 'top-start'
+const PLACEMENT_TOPEND = isRTL ? 'top-start' : 'top-end'
+const PLACEMENT_BOTTOM = isRTL ? 'bottom-end' : 'bottom-start'
+const PLACEMENT_BOTTOMEND = isRTL ? 'bottom-start' : 'bottom-end'
+const PLACEMENT_RIGHT = isRTL ? 'left-start' : 'right-start'
+const PLACEMENT_LEFT = isRTL ? 'right-start' : 'left-start'
const Default = {
offset: 0,
@@ -277,14 +278,14 @@ class Dropdown extends BaseComponent {
// Handle dropup
if (parentDropdown.classList.contains(CLASS_NAME_DROPUP)) {
- placement = this._menu.classList.contains(CLASS_NAME_MENURIGHT) ?
+ placement = this._menu.classList.contains(CLASS_NAME_MENUEND) ?
PLACEMENT_TOPEND :
PLACEMENT_TOP
- } else if (parentDropdown.classList.contains(CLASS_NAME_DROPRIGHT)) {
+ } else if (parentDropdown.classList.contains(CLASS_NAME_DROPEND)) {
placement = PLACEMENT_RIGHT
- } else if (parentDropdown.classList.contains(CLASS_NAME_DROPLEFT)) {
+ } else if (parentDropdown.classList.contains(CLASS_NAME_DROPSTART)) {
placement = PLACEMENT_LEFT
- } else if (this._menu.classList.contains(CLASS_NAME_MENURIGHT)) {
+ } else if (this._menu.classList.contains(CLASS_NAME_MENUEND)) {
placement = PLACEMENT_BOTTOMEND
}
diff --git a/js/src/modal.js b/js/src/modal.js
index a9cf8ae6c..94bf95f8a 100644
--- a/js/src/modal.js
+++ b/js/src/modal.js
@@ -13,6 +13,7 @@ import {
getElementFromSelector,
getTransitionDurationFromElement,
isVisible,
+ isRTL,
reflow,
typeCheckConfig
} from './util/index'
@@ -435,11 +436,11 @@ class Modal extends BaseComponent {
const isModalOverflowing =
this._element.scrollHeight > document.documentElement.clientHeight
- if (!this._isBodyOverflowing && isModalOverflowing) {
+ if ((!this._isBodyOverflowing && isModalOverflowing && !isRTL) || (this._isBodyOverflowing && !isModalOverflowing && isRTL)) {
this._element.style.paddingLeft = `${this._scrollbarWidth}px`
}
- if (this._isBodyOverflowing && !isModalOverflowing) {
+ if ((this._isBodyOverflowing && !isModalOverflowing && !isRTL) || (!this._isBodyOverflowing && isModalOverflowing && isRTL)) {
this._element.style.paddingRight = `${this._scrollbarWidth}px`
}
}
diff --git a/js/src/popover.js b/js/src/popover.js
index 66dcb47b9..d8bd92eef 100644
--- a/js/src/popover.js
+++ b/js/src/popover.js
@@ -115,7 +115,7 @@ class Popover extends Tooltip {
// Private
_addAttachmentClass(attachment) {
- this.getTipElement().classList.add(`${CLASS_PREFIX}-${attachment}`)
+ this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`)
}
_getContent() {
diff --git a/js/src/tooltip.js b/js/src/tooltip.js
index 25599bb42..17148ed9a 100644
--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -14,6 +14,7 @@ import {
getTransitionDurationFromElement,
getUID,
isElement,
+ isRTL,
noop,
typeCheckConfig
} from './util/index'
@@ -64,9 +65,9 @@ const DefaultType = {
const AttachmentMap = {
AUTO: 'auto',
TOP: 'top',
- RIGHT: 'right',
+ RIGHT: isRTL ? 'left' : 'right',
BOTTOM: 'bottom',
- LEFT: 'left'
+ LEFT: isRTL ? 'right' : 'left'
}
const Default = {
@@ -453,6 +454,18 @@ class Tooltip extends BaseComponent {
return title
}
+ updateAttachment(attachment) {
+ if (attachment === 'right') {
+ return 'end'
+ }
+
+ if (attachment === 'left') {
+ return 'start'
+ }
+
+ return attachment
+ }
+
// Private
_getPopperConfig(attachment) {
@@ -485,7 +498,7 @@ class Tooltip extends BaseComponent {
}
_addAttachmentClass(attachment) {
- this.getTipElement().classList.add(`${CLASS_PREFIX}-${attachment}`)
+ this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`)
}
_getOffset() {
diff --git a/js/src/util/index.js b/js/src/util/index.js
index 874827b16..96cadc65b 100644
--- a/js/src/util/index.js
+++ b/js/src/util/index.js
@@ -186,6 +186,8 @@ const onDOMContentLoaded = callback => {
}
}
+const isRTL = document.documentElement.dir === 'rtl'
+
export {
TRANSITION_END,
getUID,
@@ -201,5 +203,6 @@ export {
noop,
reflow,
getjQuery,
- onDOMContentLoaded
+ onDOMContentLoaded,
+ isRTL
}