1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-09-24 11:28:23 +02:00

Fixed expanded sections not collapsing on first click

This commit is contained in:
squidfunk 2021-03-04 18:18:56 +01:00
parent f87e32debe
commit f05c34e30d
6 changed files with 68 additions and 50 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -217,7 +217,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.52a6371e.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.da29d79a.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script>
{% endfor %}

View File

@ -20,7 +20,14 @@
* IN THE SOFTWARE.
*/
import { Observable } from "rxjs"
import { Observable, fromEvent, of } from "rxjs"
import {
mapTo,
mergeMap,
switchMap,
takeWhile,
tap
} from "rxjs/operators"
import { getElements } from "~/browser"
@ -50,13 +57,24 @@ interface PatchOptions {
export function patchIndeterminate(
{ document$ }: PatchOptions
): void {
document$.subscribe(() => {
for (const el of getElements<HTMLInputElement>(
"[data-md-state=indeterminate]"
)) {
el.setAttribute("data-md-state", "")
el.indeterminate = true
el.checked = false
}
})
document$
.pipe(
switchMap(() => of(...getElements<HTMLInputElement>(
"[data-md-state=indeterminate]"
))),
tap(el => {
el.indeterminate = true
el.checked = false
}),
mergeMap(el => fromEvent(el, "change")
.pipe(
takeWhile(() => el.hasAttribute("data-md-state")),
mapTo(el)
)
)
)
.subscribe(el => {
el.removeAttribute("data-md-state")
el.checked = false
})
}