MCPcopy Index your code
hub / github.com/angular/components / getRtlScrollAxisType

Function getRtlScrollAxisType

src/cdk/platform/features/scrolling.ts:71–114  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

69 * Firefox & Safari are NEGATED, and IE & Edge are INVERTED.
70 */
71export function getRtlScrollAxisType(): RtlScrollAxisType {
72 // We can't check unless we're on the browser. Just assume 'normal' if we're not.
73 if (typeof document !== 'object' || !document) {
74 return RtlScrollAxisType.NORMAL;
75 }
76
77 if (rtlScrollAxisType == null) {
78 // Create a 1px wide scrolling container and a 2px wide content element.
79 const scrollContainer = document.createElement('div');
80 const containerStyle = scrollContainer.style;
81 scrollContainer.dir = 'rtl';
82 containerStyle.width = '1px';
83 containerStyle.overflow = 'auto';
84 containerStyle.visibility = 'hidden';
85 containerStyle.pointerEvents = 'none';
86 containerStyle.position = 'absolute';
87
88 const content = document.createElement('div');
89 const contentStyle = content.style;
90 contentStyle.width = '2px';
91 contentStyle.height = '1px';
92
93 scrollContainer.appendChild(content);
94 document.body.appendChild(scrollContainer);
95
96 rtlScrollAxisType = RtlScrollAxisType.NORMAL;
97
98 // The viewport starts scrolled all the way to the right in RTL mode. If we are in a NORMAL
99 // browser this would mean that the scrollLeft should be 1. If it's zero instead we know we're
100 // dealing with one of the other two types of browsers.
101 if (scrollContainer.scrollLeft === 0) {
102 // In a NEGATED browser the scrollLeft is always somewhere in [-maxScrollAmount, 0]. For an
103 // INVERTED browser it is always somewhere in [0, maxScrollAmount]. We can determine which by
104 // setting to the scrollLeft to 1. This is past the max for a NEGATED browser, so it will
105 // return 0 when we read it again.
106 scrollContainer.scrollLeft = 1;
107 rtlScrollAxisType =
108 scrollContainer.scrollLeft === 0 ? RtlScrollAxisType.NEGATED : RtlScrollAxisType.INVERTED;
109 }
110
111 scrollContainer.remove();
112 }
113 return rtlScrollAxisType;
114}

Callers 2

scrollToMethod · 0.90
measureScrollOffsetMethod · 0.90

Calls 1

removeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…