Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docz-theme-default): support input method (Chinese) #182

Merged
merged 1 commit into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -139,6 +139,7 @@ interface State {
state: {
docs?: Entry[] | null
searching?: boolean
lastVal: string
}
}

Expand All @@ -161,7 +162,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 @@ -195,7 +196,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