Fixed search reset button not hiding for empty input

This commit is contained in:
squidfunk
2020-02-17 10:47:52 +01:00
parent c9d2e7774e
commit 2c0177ab56
12 changed files with 22 additions and 26 deletions

View File

@@ -21,13 +21,7 @@
*/
import { OperatorFunction, pipe } from "rxjs"
import {
mapTo,
startWith,
switchMap,
switchMapTo,
tap
} from "rxjs/operators"
import { mapTo, switchMap, switchMapTo, tap } from "rxjs/operators"
import { setElementFocus, watchSearchReset } from "observables"
@@ -43,12 +37,13 @@ import { useComponent } from "../../_"
* @return Operator function
*/
export function mountSearchReset(): OperatorFunction<HTMLElement, void> {
const query$ = useComponent<HTMLElement>("search-query")
return pipe(
switchMap(watchSearchReset),
switchMapTo(query$),
tap(setElementFocus),
mapTo(undefined),
startWith(undefined)
switchMap(el => watchSearchReset(el)
.pipe(
switchMapTo(useComponent("search-query")),
tap(setElementFocus),
mapTo(undefined)
)
)
)
}