Skip to content

Commit

Permalink
fix(docz-theme-default): support chinese input method (#182)
Browse files Browse the repository at this point in the history
support input method (Chinese) and deleting searching words backwards
  • Loading branch information
gavin1995 authored and pedronauck committed Aug 2, 2018
1 parent 24f8337 commit 94544a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ dist
.rpt2_cache
.cache
.docz
.idea
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ interface State {
state: {
docs?: Entry[] | null
searching?: boolean
lastVal: string
}
}

Expand All @@ -156,7 +157,7 @@ const mapper = {
config: <ThemeConfig />,
docs: <Docs />,
media: <Media />,
state: <State initial={{ docs: null, searching: false }} />,
state: <State initial={{ docs: null, searching: false, lastVal: '' }} />,
toggle: <Toggle initial={true} />,
}

Expand Down Expand Up @@ -190,7 +191,14 @@ export const Sidebar = () => (
const docsWithoutMenu = docs.filter((doc: Entry) => !doc.menu)

const fromMenu = (menu: string) => docs.filter(doc => doc.menu === menu)
const search = (val: string) => match(docs, val, { keys: ['name'] })
const search = (val: string) => {
const change = !val.startsWith(state.lastVal)
setState({
lastVal: val,
})
if (change) return match(initialDocs, val, { keys: ['name'] })
return match(docs, val, { keys: ['name'] })
}

const handleSearchDocs = (val: string) => {
const isEmpty = val.length === 0
Expand Down

0 comments on commit 94544a6

Please sign in to comment.