Skip to content

Commit b0dd608

Browse files
committed
use ownerDocument and convert remaining doc.dir checks
1 parent 30ad163 commit b0dd608

8 files changed

Lines changed: 18 additions & 16 deletions

File tree

‎core/src/components/col/col.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const BREAKPOINTS = ['', 'xs', 'sm', 'md', 'lg', 'xl'];
1616
shadow: true,
1717
})
1818
export class Col implements ComponentInterface {
19-
@Element() el: HTMLElement;
19+
@Element() el!: HTMLElement;
2020

2121
/**
2222
* The amount to offset the column, in terms of how many columns it should shift to the end

‎core/src/components/item-sliding/item-sliding.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export class ItemSliding implements ComponentInterface {
261261
this.leftOptions = this.rightOptions = undefined;
262262

263263
for (const option of options) {
264-
const side = isEndSide(option.side ?? option.getAttribute('side'), this.el) ? 'end' : 'start';
264+
const side = isEndSide(option.side ?? option.getAttribute('side'), option) ? 'end' : 'start';
265265

266266
if (side === 'start') {
267267
this.leftOptions = option;

‎core/src/components/popover/animations/ios.enter.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createAnimation } from '@utils/animation/animation';
22
import { getElementRoot } from '@utils/helpers';
3+
import { isRTL } from '@utils/rtl';
34

45
import type { Animation } from '../../../interface';
56
import {
@@ -30,7 +31,7 @@ const POPOVER_IOS_MIN_EDGE_MARGIN = 25;
3031
export const iosEnterAnimation = (baseEl: HTMLElement, opts?: any): Animation => {
3132
const { event: ev, size, trigger, reference, side, align } = opts;
3233
const doc = baseEl.ownerDocument as any;
33-
const isRTL = doc.dir === 'rtl';
34+
const rtl = isRTL(baseEl);
3435
const bodyWidth = doc.defaultView.innerWidth;
3536
const bodyHeight = doc.defaultView.innerHeight;
3637

@@ -45,12 +46,12 @@ export const iosEnterAnimation = (baseEl: HTMLElement, opts?: any): Animation =>
4546
const defaultPosition = {
4647
top: bodyHeight / 2 - contentHeight / 2,
4748
left: bodyWidth / 2 - contentWidth / 2,
48-
originX: isRTL ? 'right' : 'left',
49+
originX: rtl ? 'right' : 'left',
4950
originY: 'top',
5051
};
5152

5253
const results = getPopoverPosition(
53-
isRTL,
54+
rtl,
5455
contentWidth,
5556
contentHeight,
5657
arrowWidth,

‎core/src/components/popover/animations/md.enter.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createAnimation } from '@utils/animation/animation';
22
import { getElementRoot } from '@utils/helpers';
3+
import { isRTL } from '@utils/rtl';
34

45
import type { Animation } from '../../../interface';
56
import { calculateWindowAdjustment, getPopoverDimensions, getPopoverPosition, getSafeAreaInsets } from '../utils';
@@ -13,7 +14,7 @@ const POPOVER_MD_BODY_PADDING = 12;
1314
export const mdEnterAnimation = (baseEl: HTMLElement, opts?: any): Animation => {
1415
const { event: ev, size, trigger, reference, side, align } = opts;
1516
const doc = baseEl.ownerDocument as any;
16-
const isRTL = doc.dir === 'rtl';
17+
const rtl = isRTL(baseEl);
1718

1819
const bodyWidth = doc.defaultView.innerWidth;
1920
const bodyHeight = doc.defaultView.innerHeight;
@@ -27,12 +28,12 @@ export const mdEnterAnimation = (baseEl: HTMLElement, opts?: any): Animation =>
2728
const defaultPosition = {
2829
top: bodyHeight / 2 - contentHeight / 2,
2930
left: bodyWidth / 2 - contentWidth / 2,
30-
originX: isRTL ? 'right' : 'left',
31+
originX: rtl ? 'right' : 'left',
3132
originY: 'top',
3233
};
3334

3435
const results = getPopoverPosition(
35-
isRTL,
36+
rtl,
3637
contentWidth,
3738
contentHeight,
3839
0,

‎core/src/components/progress-bar/progress-bar.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import type { Color } from '../../interface';
2525
shadow: true,
2626
})
2727
export class ProgressBar implements ComponentInterface {
28-
@Element() el: HTMLElement;
28+
@Element() el!: HTMLElement;
2929

3030
/**
3131
* The state of the progress bar, based on if the time the process takes is known or not.

‎core/src/utils/helpers.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,7 @@ export const pointerCoord = (ev: any): { x: number; y: number } => {
374374
*
375375
* @param side The current side before being redefined based on the direction.
376376
* @param hostEl The component's host element. The direction is resolved from
377-
* it or its nearest ancestor that declares one. When omitted, the direction
378-
* is resolved from the document.
377+
* it or its nearest ancestor that declares one.
379378
*/
380379
export const isEndSide = (side: Side, hostEl: HTMLElement): boolean => {
381380
const rtl = isRTL(hostEl);

‎core/src/utils/input-shims/hacks/common.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isRTL } from '@utils/rtl';
2+
13
const cloneMap = new WeakMap<HTMLElement, HTMLElement>();
24

35
export const relocateInput = (
@@ -73,10 +75,9 @@ const addClone = (
7375
* Position the clone at the same horizontal offset as the native input
7476
* to prevent the placeholder from overlapping start slot content (e.g., icons).
7577
*/
76-
const doc = componentEl.ownerDocument!;
77-
const isRTL = doc.dir === 'rtl';
78+
const rtl = isRTL(componentEl);
7879

79-
if (isRTL) {
80+
if (rtl) {
8081
const parentWidth = (parentEl as HTMLElement).offsetWidth;
8182
const startOffset = parentWidth - inputEl.offsetLeft - inputEl.offsetWidth;
8283
clonedEl.style.insetInlineStart = `${startOffset}px`;
@@ -87,7 +88,7 @@ const addClone = (
8788
parentEl.appendChild(clonedEl);
8889
cloneMap.set(componentEl, clonedEl);
8990

90-
const tx = isRTL ? 9999 : -9999;
91+
const tx = rtl ? 9999 : -9999;
9192
componentEl.style.pointerEvents = 'none';
9293
inputEl.style.transform = `translate3d(${tx}px,${inputRelativeY}px,0) scale(0)`;
9394
};

‎core/src/utils/rtl/dir.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ export const isRTL = (hostEl: Element): boolean => {
2020
return false;
2121
}
2222
}
23-
return document?.dir?.toLowerCase() === 'rtl';
23+
return hostEl.ownerDocument?.dir?.toLowerCase() === 'rtl';
2424
};

0 commit comments

Comments
 (0)