Skip to content

Commit

Permalink
Merge branch 'main' into feat/fluid-as-alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
mimarz authored Mar 20, 2024
2 parents 822cd9d + 6bbb3b7 commit 18e518d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Preview.args = {
disabled: false,
hideLabel: false,
hideChips: false,
hideClearButton: false,
virtual: false,
description: 'Velg et sted',
size: 'medium',
Expand Down
19 changes: 17 additions & 2 deletions packages/react/src/components/form/Combobox/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,19 @@ export type ComboboxProps = {
/**
* Label for the clear button
* @default 'Fjern alt'
* @deprecated Use `clearButtonLabel` instead
*/
cleanButtonLabel?: string;
/**
* Hides the clear button
* @default false
*/
hideClearButton?: boolean;
/**
* Label for the clear button
* @default 'Fjern alt'
*/
clearButtonLabel?: string;
/**
* Enables virtualizing of options list.
* @see https://tanstack.com/virtual
Expand Down Expand Up @@ -150,6 +161,8 @@ export const Combobox = forwardRef<HTMLInputElement, ComboboxProps>(
readOnly = false,
hideChips = false,
cleanButtonLabel = 'Fjern alt',
clearButtonLabel = 'Fjern alt',
hideClearButton = false,
error,
errorId,
id,
Expand Down Expand Up @@ -457,7 +470,8 @@ export const Combobox = forwardRef<HTMLInputElement, ComboboxProps>(
htmlSize,
optionValues,
hideChips,
cleanButtonLabel,
clearButtonLabel: cleanButtonLabel || clearButtonLabel,
hideClearButton,
listId,
setInputValue,
setActiveIndex,
Expand Down Expand Up @@ -606,7 +620,8 @@ type ComboboxContextType = {
error: ComboboxProps['error'];
htmlSize: ComboboxProps['htmlSize'];
hideChips: NonNullable<ComboboxProps['hideChips']>;
cleanButtonLabel: NonNullable<ComboboxProps['cleanButtonLabel']>;
clearButtonLabel: NonNullable<ComboboxProps['clearButtonLabel']>;
hideClearButton: NonNullable<ComboboxProps['hideClearButton']>;
options: Option[];
selectedOptions: Option[];
size: NonNullable<ComboboxProps['size']>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ComboboxClearButton = () => {
size,
readOnly,
disabled,
cleanButtonLabel,
clearButtonLabel,
inputRef,
setSelectedOptions,
setInputValue,
Expand Down Expand Up @@ -48,7 +48,7 @@ export const ComboboxClearButton = () => {
}
}}
type='button'
aria-label={cleanButtonLabel}
aria-label={clearButtonLabel}
>
<XMarkIcon
fontSize='1.5em'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const ComboboxInput = ({
htmlSize,
options,
hideChips,
hideClearButton,
setOpen,
setActiveIndex,
handleKeyDown,
Expand Down Expand Up @@ -107,6 +108,9 @@ export const ComboboxInput = ({
}
};

const showClearButton =
multiple && !hideClearButton && selectedOptions.length > 0;

return (
<Box
/* Props from floating-ui */
Expand Down Expand Up @@ -168,7 +172,7 @@ export const ComboboxInput = ({
/>
</div>
{/* Clear button if we are in multiple mode and have at least one active value */}
{multiple && selectedOptions.length > 0 && <ComboboxClearButton />}
{showClearButton && <ComboboxClearButton />}
{/* Arrow for combobox. Click is handled by the wrapper */}
<div className={classes.arrow}>
{open ? (
Expand Down

0 comments on commit 18e518d

Please sign in to comment.