Skip to content

Commit

Permalink
ui-core: make clear button appear when a default value is provided
Browse files Browse the repository at this point in the history
Signed-off-by: SarahBellaha <sarah.bellaha@sncf.fr>
  • Loading branch information
SarahBellaha committed Oct 9, 2024
1 parent 97451f1 commit 16a2060
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ui-core/src/components/inputs/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ const ComboBox = <T,>({
customLabel,
numberOfSuggestionsToShow = 5,
exactSearch = false,
value,
value = '',
small,
onSelectSuggestion,
disableDefaultFilter = false,
...inputProps
}: ComboBoxProps<T>) => {
const [filteredSuggestions, setFilteredSuggestions] = useState<T[]>([]);
const [activeSuggestionIndex, setActiveSuggestionIndex] = useState(-1);
const [inputValue, setInputValue] = useState(value || '');
const [inputValue, setInputValue] = useState(value);
const [selectedOption, setSelectedOption] = useState<T | null>(null);
const [isInputFocused, setIsInputFocused] = useState(false);

Expand Down Expand Up @@ -84,7 +84,7 @@ const ComboBox = <T,>({
};

const icons = [
...(selectedOption
...(selectedOption || suggestions.some((suggestion) => getSuggestionLabel(suggestion) === value)
? [
{
icon: <X size={small ? 'sm' : 'lg'} />,
Expand Down
2 changes: 1 addition & 1 deletion ui-core/src/stories/ComboBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const WithDefaultValue: Story = {
args: {
label: 'Your name',
type: 'text',
value: 'Manuéla',
value: 'Manolo',
},
};

Expand Down

0 comments on commit 16a2060

Please sign in to comment.