Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ca40174
Add `useCombobox` hook, extending `@github/combobox-nav`
iansan5653 Jun 14, 2022
9ef18e3
Add `useSyntheticChange` hook
iansan5653 Jun 14, 2022
d14418e
Add `InlineAutocomplete` component
iansan5653 Jun 14, 2022
34ab6f3
Refactor and improve comments
iansan5653 Jun 16, 2022
f63e606
Remove extra type
iansan5653 Jun 16, 2022
2ef8d23
Add story and make it work with `FormControl`
iansan5653 Jun 16, 2022
02d8d1a
Add to main exports
iansan5653 Jun 16, 2022
ed4b12e
Add MDX file
iansan5653 Jun 16, 2022
c9b8ead
Merge branch 'main' of https://github.com/primer/react into add-inlin…
iansan5653 Jun 29, 2022
b110c98
Remove unecessary ID on textarea in story
iansan5653 Jun 29, 2022
c029876
Remove version-lock from new dependencies
iansan5653 Jun 29, 2022
d8dad97
Make type of render function more specific
iansan5653 Jun 29, 2022
375d6c9
Add unit tests
iansan5653 Jun 30, 2022
c53bf3d
Simplify `useCombobox` and use `navigate` to focus first item
iansan5653 Jul 1, 2022
7b55370
Fix tests by wrapping `userEvent.type` in `act`
iansan5653 Jul 12, 2022
1b39b54
Fix preventing blur when tabbing from loading state
iansan5653 Jul 12, 2022
0a30f05
Delete unused imports
iansan5653 Jul 12, 2022
9a97bdf
Change interfaces out for object types
iansan5653 Jul 12, 2022
af4ea26
Add accessible live status message to describe suggestions
iansan5653 Jul 12, 2022
431f1eb
Dynamically assign the combobox role to avoid treating the textarea a…
iansan5653 Jul 12, 2022
20b619e
Shorten & revise status message
iansan5653 Jul 15, 2022
010674c
Merge branch 'main' of https://github.com/primer/react into add-inlin…
iansan5653 Jul 19, 2022
b7ba947
Move to drafts
iansan5653 Jul 19, 2022
b3f0808
Move docs to drafts
iansan5653 Jul 19, 2022
de624b4
Fix import in docs
iansan5653 Jul 19, 2022
f0ccf34
Update combobox-nav dependency
iansan5653 Jul 20, 2022
ebd1c6f
Add option to control whether `Tab` key inserts suggestions
iansan5653 Jul 20, 2022
90bcff5
Style the defaulted-to first option differently from the selected option
iansan5653 Jul 20, 2022
82ba405
Update combobox-nav dependency
iansan5653 Jul 22, 2022
3373f33
Merge branch 'main' of https://github.com/primer/react into add-inlin…
iansan5653 Jul 28, 2022
0ee19db
Update and fix unit tests
iansan5653 Jul 28, 2022
af9bcc6
Remove unused import (fix lint error)
iansan5653 Jul 29, 2022
d37426d
docs: add drafts metastring
siddharthkp Aug 1, 2022
b6d2e28
Remove `selectionVariant` from suggestions list
iansan5653 Aug 1, 2022
841b41c
Merge branch 'add-inline-autocomplete-component' of https://github.co…
iansan5653 Aug 1, 2022
ac68a54
Merge branch 'main' of https://github.com/primer/react into add-inlin…
iansan5653 Aug 1, 2022
17b3747
Add `install:docs` script
iansan5653 Aug 1, 2022
1b7cb9c
Add more examples to docs
iansan5653 Aug 1, 2022
07af717
Add more stories
iansan5653 Aug 1, 2022
0a608ab
Fix _another_ bug with the caret-coordinates utility and single-line …
iansan5653 Aug 1, 2022
f48c8e5
Move component & hooks to drafts folder
iansan5653 Aug 1, 2022
dcfbffc
Move stories & tests into drafts
iansan5653 Aug 1, 2022
ed30cc6
Remove non-null assertions in tests
iansan5653 Aug 1, 2022
468b5a9
Move `textarea-caret` type declaration to `@types`
iansan5653 Aug 1, 2022
592b179
Add props table
iansan5653 Aug 1, 2022
69f3203
Fix TS issue
iansan5653 Aug 1, 2022
1456caf
Create cuddly-bags-sort.md
iansan5653 Aug 2, 2022
0d4c896
Merge branch 'main' into add-inline-autocomplete-component
siddharthkp Aug 2, 2022
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
5 changes: 5 additions & 0 deletions .changeset/cuddly-bags-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Add `InlineAutocomplete` component, `useCombobox` hook, and `useSyntheticChange` hook to drafts
Empty file added @types/@koddsson/index.d.ts
Empty file.
11 changes: 11 additions & 0 deletions @types/@koddsson/textarea-caret/index.d.ts
Original file line number Diff line number Diff line change
@@ -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
}
162 changes: 162 additions & 0 deletions docs/content/drafts/InlineAutocomplete.mdx
Original file line number Diff line number Diff line change
@@ -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

<Note variant="warning">

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.

</Note>

### 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 (
<InlineAutocomplete
triggers={[{triggerChar: '#'}]}
suggestions={suggestions}
onShowSuggestions={({query}) => setSuggestions(options.filter(tag => tag.includes(query)))}
onHideSuggestions={() => setSuggestions([])}
>
<Textarea />
</InlineAutocomplete>
)
}

render(SimpleExample)
```

### Single-line input

```javascript live noinline drafts
const options = ['javascript', 'typescript', 'css', 'html', 'webassembly']

const SimpleExample = () => {
const [suggestions, setSuggestions] = React.useState([])

return (
<InlineAutocomplete
triggers={[{triggerChar: '#'}]}
suggestions={suggestions}
onShowSuggestions={({query}) => setSuggestions(options.filter(tag => tag.includes(query)))}
onHideSuggestions={() => setSuggestions([])}
>
<TextInput />
</InlineAutocomplete>
)
}

render(SimpleExample)
```

### Labelled

```javascript live noinline drafts
const options = ['javascript', 'typescript', 'css', 'html', 'webassembly']

const SimpleExample = () => {
const [suggestions, setSuggestions] = React.useState([])

return (
<FormControl>
<FormControl.Label>Example</FormControl.Label>
<InlineAutocomplete
triggers={[{triggerChar: '#'}]}
suggestions={suggestions}
onShowSuggestions={({query}) => setSuggestions(options.filter(tag => tag.includes(query)))}
onHideSuggestions={() => setSuggestions([])}
>
<Textarea />
</InlineAutocomplete>
</FormControl>
)
}

render(SimpleExample)
```

## Props

<PropsTable>
<PropsTableRow
name="children"
required
type="React.ReactNode"
description="An `input` or `textarea` compatible component to extend. A compatible component is any component that forwards a ref and props to an underlying `input` or `textarea` element, including but not limited to `Input`, `TextArea`, `input`, `textarea`, `styled.input`, and `styled.textarea`. If the child is not compatible, a runtime `TypeError` will be thrown."
/>
<PropsTableRow
name="triggers"
required
type="Array<Trigger>"
description="Register the triggers that can cause suggestions to appear."
/>
<PropsTableRow
name="onShowSuggestions"
type="(event: ShowSuggestionsEvent) => void"
required
description="Called when a valid suggestion query is updated. This should be handled by setting the `suggestions` prop accordingly."
/>
<PropsTableRow
name="onShowSuggestions"
type="() => void"
required
description="Called when suggestions should be hidden. Set `suggestions` to `null` or an empty array in this case."
/>
<PropsTableRow
name="suggestions"
type="Suggestion[] | null | 'loading'"
required
description="The currently visible list of suggestions. If `loading`, a loading indicator will be shown. If `null` or empty, the list will be hidden. Suggestion sort will be preserved. Typically, this should not contain more than five or so suggestions."
/>
<PropsTableRow
name="tabInsertsSuggestions"
type="boolean"
defaultValue="false"
description="If `true`, suggestions will be applied with both `Tab` and `Enter`, instead of just `Enter`. This may be expected behavior for users used to IDEs, but use caution when hijacking browser tabbing capability."
/>
<PropsTableSxRow />
</PropsTable>

## Status

<ComponentChecklist
items={{
propsDocumented: false,
noUnnecessaryDeps: true,
adaptsToThemes: true,
adaptsToScreenSizes: true,
fullTestCoverage: false,
usedInProduction: true,
usageExamplesDocumented: false,
hasStorybookStories: false,
designReviewed: false,
a11yReviewed: false,
stableApi: false,
addressedApiFeedback: false,
hasDesignGuidelines: false,
hasFigmaComponent: false
}}
/>
Loading