Skip to content

Commit

Permalink
fix: drop unused hide-empty property
Browse files Browse the repository at this point in the history
BREAKING CHANGE: hide-empty has been removed
  • Loading branch information
cristinecula committed Nov 16, 2024
1 parent c241440 commit 58d3829
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 41 deletions.
1 change: 0 additions & 1 deletion src/autocomplete/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ const autocomplete = <I>(props: AProps<I>) => {
'preserve-order',
'keep-opened',
'keep-query',
'hide-empty',
'default-index',
'item-height',
'item-limit',
Expand Down
8 changes: 1 addition & 7 deletions src/autocomplete/use-autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export interface Props<I> extends Base<I> {
textProperty?: string;
textual?: (prop?: string) => (i: I) => string;
valueProperty?: string;
hideEmpty?: boolean;
disabled?: boolean;
onFocus?: (focused?: boolean) => void;
preserveOrder?: boolean;
Expand All @@ -55,7 +54,6 @@ export const useAutocomplete = <I>({
textProperty,
textual: _textual,
valueProperty,
hideEmpty,
keepOpened,
keepQuery,
preserveOrder,
Expand Down Expand Up @@ -94,7 +92,6 @@ export const useAutocomplete = <I>({
empty,
limit,
value,
hideEmpty,
onChange,
onText,
});
Expand Down Expand Up @@ -122,9 +119,7 @@ export const useAutocomplete = <I>({
value,
source$,
items: useMemo(() => {
if (!active || (hideEmpty && empty)) {
return EMPTY;
}
if (!active) return EMPTY;

const items = preserveOrder
? options
Expand All @@ -136,7 +131,6 @@ export const useAutocomplete = <I>({
active,
query,
textual,
hideEmpty,
empty,
value,
preserveOrder,
Expand Down
12 changes: 2 additions & 10 deletions src/autocomplete/use-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import { useMeta } from '@neovici/cosmoz-utils/hooks/use-meta';
export interface Props<I> {
focused?: boolean;
empty?: boolean;
hideEmpty?: boolean;
value: I | I[];
limit?: number;
onChange: (v: I[]) => void;
onText: (s: string) => void;
}

export const useKeys = <I>({ focused, empty, ...info }: Props<I>) => {
export const useKeys = <I>({ focused, empty, ...rest }: Props<I>) => {
const enabled = focused && empty,
meta = useMeta(info);
meta = useMeta(rest);
useEffect(() => {
if (!enabled) {
return;
Expand All @@ -32,13 +31,6 @@ export const useKeys = <I>({ focused, empty, ...info }: Props<I>) => {
(key === 'Backspace' || (isOne && key.length === 1))
) {
return meta.onChange(values.slice(0, -1));
} else if (
meta.hideEmpty &&
values.length < 1 &&
['Up', 'ArrowUp', 'Down', 'ArrowDown'].includes(key)
) {
meta.onText(' ');
e.preventDefault();
}
};

Expand Down
23 changes: 0 additions & 23 deletions stories/cosmoz-autocomplete.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const Autocomplete = ({
min,
label = '',
value = [],
hideEmpty = false,
disabled = false,
placeholder = '',
defaultIndex = 0,
Expand Down Expand Up @@ -59,7 +58,6 @@ const Autocomplete = ({
.value=${value}
.min=${min}
.defaultIndex=${defaultIndex}
?hide-empty=${hideEmpty}
?disabled=${disabled}
?show-single=${showSingle}
?preserve-order=${preserveOrder}
Expand All @@ -78,7 +76,6 @@ const ContourAutocomplete = ({
min,
label = '',
value = [],
hideEmpty = false,
disabled = false,
placeholder = '',
defaultIndex = 0,
Expand Down Expand Up @@ -119,7 +116,6 @@ const ContourAutocomplete = ({
.value=${value}
.min=${min}
.defaultIndex=${defaultIndex}
?hide-empty=${hideEmpty}
?disabled=${disabled}
?show-single=${showSingle}
?preserve-order=${preserveOrder}
Expand Down Expand Up @@ -156,7 +152,6 @@ export default {
control: 'number',
description: 'The default index of the source array',
},
hideEmpty: { control: 'boolean' },
disabled: {
control: 'boolean',
description:
Expand Down Expand Up @@ -218,24 +213,6 @@ export const Single = {
},
};

export const HideEmpty = {
args: {
label: 'Choose color',
source: colors,
textProperty: 'text',
limit: 1,
value: [colors[2]],
hideEmpty: true,
},
parameters: {
docs: {
description: {
story: 'Hide the empty value',
},
},
},
};

export const DefaultIndex = {
args: {
label: 'Choose color',
Expand Down

0 comments on commit 58d3829

Please sign in to comment.