Skip to content

Commit a32760b

Browse files
committed
Fixed tab indicator animation for right-to-left languages
1 parent 4b2a97a commit a32760b

File tree

9 files changed

+83
-57
lines changed

9 files changed

+83
-57
lines changed

Diff for: material/assets/javascripts/bundle.1cbe63b4.min.js renamed to material/assets/javascripts/bundle.f881a9a8.min.js

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: material/assets/javascripts/bundle.1cbe63b4.min.js.map renamed to material/assets/javascripts/bundle.f881a9a8.min.js.map

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: material/assets/stylesheets/main.ffa0dd14.min.css renamed to material/assets/stylesheets/main.3714f473.min.css

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: material/assets/stylesheets/main.ffa0dd14.min.css.map renamed to material/assets/stylesheets/main.3714f473.min.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: material/base.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
{% endif %}
3535
{% endblock %}
3636
{% block styles %}
37-
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.ffa0dd14.min.css' | url }}">
37+
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.3714f473.min.css' | url }}">
3838
{% if config.theme.palette %}
3939
{% set palette = config.theme.palette %}
4040
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.e6a45f82.min.css' | url }}">
@@ -213,7 +213,7 @@
213213
</script>
214214
{% endblock %}
215215
{% block scripts %}
216-
<script src="{{ 'assets/javascripts/bundle.1cbe63b4.min.js' | url }}"></script>
216+
<script src="{{ 'assets/javascripts/bundle.f881a9a8.min.js' | url }}"></script>
217217
{% for path in config["extra_javascript"] %}
218218
<script src="{{ path | url }}"></script>
219219
{% endfor %}

Diff for: src/assets/javascripts/components/content/tabs/index.ts

+37-21
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,27 @@
2323
import {
2424
Observable,
2525
Subject,
26+
animationFrameScheduler,
27+
auditTime,
28+
combineLatest,
2629
defer,
2730
finalize,
2831
fromEvent,
2932
map,
3033
mapTo,
3134
merge,
3235
startWith,
36+
takeLast,
37+
takeUntil,
3338
tap
3439
} from "rxjs"
3540

3641
import {
3742
getElement,
3843
getElementOffset,
3944
getElementSize,
40-
getElements
45+
getElements,
46+
watchElementSize
4147
} from "~/browser"
4248

4349
import { Component } from "../../_"
@@ -97,33 +103,43 @@ export function watchContentTabs(
97103
export function mountContentTabs(
98104
el: HTMLElement
99105
): Observable<Component<ContentTabs>> {
106+
const { matches: reduce } = matchMedia("(prefers-reduced-motion)")
107+
108+
/* Mount component on subscription */
100109
const container = getElement(".tabbed-labels", el)
101110
return defer(() => {
102111
const push$ = new Subject<ContentTabs>()
103-
push$.subscribe({
112+
combineLatest([push$, watchElementSize(el)])
113+
.pipe(
114+
auditTime(1, animationFrameScheduler),
115+
takeUntil(push$.pipe(takeLast(1)))
116+
)
117+
.subscribe({
104118

105-
/* Handle emission */
106-
next({ active }) {
107-
const offset = getElementOffset(active)
108-
const { width } = getElementSize(active)
119+
/* Handle emission */
120+
next([{ active }]) {
121+
const offset = getElementOffset(active)
122+
if (!reduce) {
123+
const { width } = getElementSize(active)
109124

110-
/* Set tab indicator offset and width */
111-
el.style.setProperty("--md-indicator-x", `${offset.x}px`)
112-
el.style.setProperty("--md-indicator-width", `${width}px`)
125+
/* Set tab indicator offset and width */
126+
el.style.setProperty("--md-indicator-x", `${offset.x}px`)
127+
el.style.setProperty("--md-indicator-width", `${width}px`)
128+
}
113129

114-
/* Smoothly scroll container */
115-
container.scrollTo({
116-
behavior: "smooth",
117-
left: offset.x
118-
})
119-
},
130+
/* Smoothly scroll container */
131+
container.scrollTo({
132+
behavior: "smooth",
133+
left: offset.x
134+
})
135+
},
120136

121-
/* Handle complete */
122-
complete() {
123-
el.style.removeProperty("--md-indicator-x")
124-
el.style.removeProperty("--md-indicator-width")
125-
}
126-
})
137+
/* Handle complete */
138+
complete() {
139+
el.style.removeProperty("--md-indicator-x")
140+
el.style.removeProperty("--md-indicator-width")
141+
}
142+
})
127143

128144
/* Create and return component */
129145
return watchContentTabs(el)

Diff for: src/assets/javascripts/components/top/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export function mountBackToTop(
148148
/* Handle complete */
149149
complete() {
150150
el.style.top = ""
151-
el.removeAttribute("data-md-state")
151+
el.setAttribute("data-md-state", "hidden")
152152
el.removeAttribute("tabindex")
153153
}
154154
})

Diff for: src/assets/stylesheets/main/extensions/pymdownx/_tabbed.scss

+28-18
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,29 @@
8787
display: contents;
8888
}
8989

90-
// [js]: Show animated tab indicator
91-
.js & {
92-
position: relative;
93-
94-
// Tab indicator
95-
&::after {
96-
position: absolute;
97-
bottom: 0;
98-
display: block;
99-
width: var(--md-indicator-width);
100-
height: 2px;
101-
background: var(--md-accent-fg-color);
102-
transform: translateX(var(--md-indicator-x));
103-
transition:
104-
width 250ms,
105-
transform 250ms;
106-
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
107-
content: "";
90+
// [screen and no reduced motion]: Disable animation
91+
@media screen and (prefers-reduced-motion: no-preference) {
92+
93+
// [js]: Show animated tab indicator
94+
.js & {
95+
position: relative;
96+
97+
// Tab indicator
98+
&::before {
99+
position: absolute;
100+
bottom: 0;
101+
left: 0;
102+
display: block;
103+
width: var(--md-indicator-width);
104+
height: 2px;
105+
background: var(--md-accent-fg-color);
106+
transform: translateX(var(--md-indicator-x));
107+
transition:
108+
width 250ms,
109+
transform 250ms;
110+
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
111+
content: "";
112+
}
108113
}
109114
}
110115

@@ -229,6 +234,11 @@
229234
@media screen {
230235
color: var(--md-accent-fg-color);
231236

237+
// [reduced motion]: Show border
238+
@media (prefers-reduced-motion) {
239+
border-color: var(--md-accent-fg-color);
240+
}
241+
232242
// [no-js]: Show border (indicator is animated with JavaScript)
233243
.no-js & {
234244
border-color: var(--md-accent-fg-color);

Diff for: src/assets/stylesheets/main/layout/_tooltip.scss

+5-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
max-height 0ms 250ms,
8686
z-index 250ms;
8787

88-
// [reduced-motion]: Disable animation
88+
// [reduced motion]: Disable animation
8989
@media (prefers-reduced-motion) {
9090
transition: none;
9191
}
@@ -101,7 +101,7 @@
101101
max-height 250ms,
102102
z-index 0ms;
103103

104-
// [reduced-motion]: Disable animation
104+
// [reduced motion]: Disable animation
105105
@media (prefers-reduced-motion) {
106106
transition: none;
107107
}
@@ -194,7 +194,7 @@
194194
animation: pulse 2000ms infinite;
195195
content: "";
196196

197-
// [reduced-motion]: Disable animation
197+
// [reduced motion]: Disable animation
198198
@media (prefers-reduced-motion) {
199199
transition: none;
200200
animation: none;
@@ -212,7 +212,7 @@
212212
background-color 250ms;
213213
animation: none;
214214

215-
// [reduced-motion]: Disable animation
215+
// [reduced motion]: Disable animation
216216
@media (prefers-reduced-motion) {
217217
transition: none;
218218
}
@@ -225,7 +225,7 @@
225225
transition: transform 400ms cubic-bezier(0.1, 0.7, 0.1, 1);
226226
content: attr(data-md-annotation-id);
227227

228-
// [reduced-motion]: Disable animation
228+
// [reduced motion]: Disable animation
229229
@media (prefers-reduced-motion) {
230230
transition: none;
231231
}

0 commit comments

Comments
 (0)