-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from szhsin/feat/auto-focus
feat: auto focus
- Loading branch information
Showing
22 changed files
with
174 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const autoFocus = ({ | ||
getFocusItem | ||
}) => ({ | ||
setFocusItem | ||
}) => ({ | ||
getInputProps: () => ({ | ||
onChange: async e => { | ||
const nextValue = e.target.value; | ||
if (nextValue) { | ||
const item = await getFocusItem(nextValue); | ||
item && setFocusItem(item); | ||
} | ||
} | ||
}) | ||
}); | ||
|
||
export { autoFocus }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { mergeModules } from '../../utils/mergeModules.js'; | ||
import { autocomplete } from './autocomplete.js'; | ||
import { inline } from '../atom/inline.js'; | ||
import { autoInline } from '../atom/autoInline.js'; | ||
|
||
const supercomplete = ({ | ||
getInlineItem, | ||
getFocusItem, | ||
...rest | ||
}) => mergeModules(autocomplete({ | ||
...rest, | ||
rovingText: true | ||
}), inline({ | ||
getInlineItem | ||
}), autoInline({ | ||
getFocusItem | ||
})); | ||
|
||
export { supercomplete }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
mergeModules, | ||
MergedFeature, | ||
FeatureProps, | ||
AutocompleteFeature, | ||
AutoFocusFeature, | ||
autocomplete, | ||
autoFocus | ||
} from '@szhsin/react-autocomplete'; | ||
|
||
type AutocompleteFocusFeature<T> = MergedFeature< | ||
T, | ||
[AutocompleteFeature<T>, AutoFocusFeature<T>] | ||
>; | ||
|
||
const autocompleteFocus = <T>(props: FeatureProps<T>): AutocompleteFocusFeature<T> => | ||
mergeModules(autocomplete<T>(props), autoFocus<T>(props)); | ||
|
||
export { autocompleteFocus }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Feature, GetPropsFunctions, FeatureProps } from '../../common'; | ||
|
||
type AutoFocusFeature<T> = Feature<T, Pick<GetPropsFunctions<T>, 'getInputProps'>>; | ||
|
||
const autoFocus = | ||
<T>({ getFocusItem }: Pick<FeatureProps<T>, 'getFocusItem'>): AutoFocusFeature<T> => | ||
({ setFocusItem }) => ({ | ||
getInputProps: () => ({ | ||
onChange: async (e) => { | ||
const nextValue = e.target.value; | ||
if (nextValue) { | ||
const item = await getFocusItem(nextValue); | ||
item && setFocusItem(item); | ||
} | ||
} | ||
}) | ||
}); | ||
|
||
export { type AutoFocusFeature, autoFocus }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.