Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
fix(core): rename showCompletion to enableCompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Aug 25, 2020
1 parent a87a5d7 commit 07b46af
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ The text that appears in the search box input when there is no query.

It is fowarded to the [`input`'s placeholder](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefplaceholder).

#### `showCompletion`
#### `enableCompletion`

> `boolean` | defaults to `false`
Whether to show the highlighted suggestion as completion in the input.

![`showCompletion` preview](https://user-images.githubusercontent.com/6137112/68124812-7e989800-ff10-11e9-88a5-f28c1466b665.png)
![`enableCompletion` preview](https://user-images.githubusercontent.com/6137112/68124812-7e989800-ff10-11e9-88a5-f28c1466b665.png)

#### `openOnFocus`

Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-core/src/getCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function getCompletion<TItem>({
props,
}: GetCompletionProps<TItem>): string | null {
if (
props.showCompletion === false ||
props.enableCompletion === false ||
state.isOpen === false ||
state.highlightedIndex === null ||
state.status === 'stalled'
Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-core/src/getDefaultProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function getDefaultProps<TItem>(
placeholder: '',
autoFocus: false,
defaultHighlightedIndex: null,
showCompletion: false,
enableCompletion: false,
stallThreshold: 300,
environment,
shouldDropdownShow: ({ state }) => getItemsCount(state) > 0,
Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-core/src/getPropGetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
const { inputElement, maxLength = 512, ...rest } = providedProps || {};

return {
'aria-autocomplete': props.showCompletion ? 'both' : 'list',
'aria-autocomplete': props.enableCompletion ? 'both' : 'list',
'aria-activedescendant':
store.getState().isOpen && store.getState().highlightedIndex !== null
? `${props.id}-item-${store.getState().highlightedIndex}`
Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-core/src/onKeyDown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function onKeyDown<TItem>({
(event.key === 'ArrowRight' &&
(event.target as HTMLInputElement).selectionStart ===
store.getState().query.length)) &&
props.showCompletion &&
props.enableCompletion &&
store.getState().highlightedIndex !== null
) {
event.preventDefault();
Expand Down
4 changes: 2 additions & 2 deletions packages/autocomplete-core/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export interface PublicAutocompleteOptions<TItem> {
*
* @default false
*/
showCompletion?: boolean;
enableCompletion?: boolean;
/**
* Whether to open the dropdown on focus when there's no query.
*
Expand Down Expand Up @@ -248,7 +248,7 @@ export interface AutocompleteOptions<TItem> {
placeholder: string;
autoFocus: boolean;
defaultHighlightedIndex: number | null;
showCompletion: boolean;
enableCompletion: boolean;
openOnFocus: boolean;
stallThreshold: number;
initialState: AutocompleteState<TItem>;
Expand Down
4 changes: 2 additions & 2 deletions packages/autocomplete-js/src/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function autocomplete<TItem>({
function render(state: AutocompleteState<TItem>) {
input.value = state.query;

if (props.showCompletion) {
if (props.enableCompletion) {
completion.textContent = state.completion;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ export function autocomplete<TItem>({
}

form.appendChild(label);
if (props.showCompletion) {
if (props.enableCompletion) {
inputWrapper.appendChild(completion);
}
inputWrapper.appendChild(input);
Expand Down
2 changes: 1 addition & 1 deletion packages/website/docs/createAutocomplete.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The default item index to pre-select.

We recommend using `0` when the query typed aims at opening suggestion links, without triggering an actual search.

### `showCompletion`
### `enableCompletion`

> `boolean` | defaults to `false`
Expand Down
6 changes: 3 additions & 3 deletions stories/react.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ storiesOf('React', module)
render(
<Autocomplete
placeholder="Search items…"
showCompletion={true}
enableCompletion={true}
dropdownContainer={dropdownContainer}
defaultHighlightedIndex={null}
getSources={() => {
Expand Down Expand Up @@ -58,7 +58,7 @@ storiesOf('React', module)
render(
<Autocomplete
placeholder="Search items…"
showCompletion={true}
enableCompletion={true}
dropdownContainer={dropdownContainer}
getSources={() => {
return [
Expand Down Expand Up @@ -248,7 +248,7 @@ storiesOf('React', module)
render(
<Autocomplete
placeholder="Search items…"
showCompletion={true}
enableCompletion={true}
dropdownContainer={dropdownContainer}
defaultHighlightedIndex={0}
openOnFocus={true}
Expand Down

0 comments on commit 07b46af

Please sign in to comment.