diff --git a/.changeset/cuddly-bags-sort.md b/.changeset/cuddly-bags-sort.md new file mode 100644 index 00000000000..d9ae0c3c250 --- /dev/null +++ b/.changeset/cuddly-bags-sort.md @@ -0,0 +1,5 @@ +--- +"@primer/react": patch +--- + +Add `InlineAutocomplete` component, `useCombobox` hook, and `useSyntheticChange` hook to drafts diff --git a/@types/@koddsson/index.d.ts b/@types/@koddsson/index.d.ts new file mode 100644 index 00000000000..e69de29bb2d diff --git a/@types/@koddsson/textarea-caret/index.d.ts b/@types/@koddsson/textarea-caret/index.d.ts new file mode 100644 index 00000000000..c2505997701 --- /dev/null +++ b/@types/@koddsson/textarea-caret/index.d.ts @@ -0,0 +1,11 @@ +declare module '@koddsson/textarea-caret' { + export interface CaretCoordinates { + top: number + left: number + height: number + } + export default function getCaretCoordinates( + input: HTMLTextAreaElement | HTMLInputElement, + index: number + ): CaretCoordinates +} diff --git a/docs/content/drafts/InlineAutocomplete.mdx b/docs/content/drafts/InlineAutocomplete.mdx new file mode 100644 index 00000000000..32fa20c9dcf --- /dev/null +++ b/docs/content/drafts/InlineAutocomplete.mdx @@ -0,0 +1,162 @@ +--- +title: InlineAutocomplete +componentId: inline_autocomplete +status: Draft +description: Provides inline auto completion suggestions for an input or textarea. +source: https://github.com/primer/react/tree/main/src/InlineAutocomplete +storybook: '/react/storybook?path=/story/forms-inlineautocomplete--default' +--- + +```js +import {InlineAutocomplete} from '@primer/react/drafts' +``` + +The `InlineAutocomplete` component extends an `Input` or `Textarea` component to provide inline suggestions, similar to those provided by a code editor. + +## Examples + + + +Input components **must always** be accompanied by a corresponding label to improve support for assistive +technologies. Examples below are provided for conciseness and may not reflect accessibility best practices. + +`InlineAutocomplete` can be used with the [`FormControl`](/FormControl) component to render a corresponding label. + + + +### Multi-line input + +Try typing a `#` symbol to see suggestions. Use `Enter` or click to apply a suggestion. + +```javascript live noinline drafts +const options = ['javascript', 'typescript', 'css', 'html', 'webassembly'] + +const SimpleExample = () => { + const [suggestions, setSuggestions] = React.useState([]) + + return ( + setSuggestions(options.filter(tag => tag.includes(query)))} + onHideSuggestions={() => setSuggestions([])} + > +