Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(primitives): fixes ts strict errors Alert/Autocomplete #3292

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
fix(primitives): fixes ts strict errors Alert/Autocomplete
  • Loading branch information
reesscot committed Jan 11, 2023
commit 7f15a43fe04c3c8d293ad04b4f60dbab3d7cee11
64 changes: 31 additions & 33 deletions packages/react/src/primitives/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,38 @@ const AlertPrimitive: Primitive<AlertProps, typeof Flex> = (
}
}, [setDismissed, onDismiss, dismissed]);

return (
!dismissed && (
Copy link
Contributor Author

@reesscot reesscot Jan 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript didn't like this because it means Alert can return false, which is not a valid ReactElement

<Flex
className={classNames(
ComponentClassNames.Alert,
className,
classNameModifier(ComponentClassNames.Alert, variation)
return !dismissed ? (
<Flex
className={classNames(
ComponentClassNames.Alert,
className,
classNameModifier(ComponentClassNames.Alert, variation)
)}
data-variation={variation}
ref={ref}
role="alert"
{...rest}
>
{hasIcon && <AlertIcon variation={variation} ariaHidden />}
<View flex="1">
{heading && (
<View className={ComponentClassNames.AlertHeading}>{heading}</View>
)}
data-variation={variation}
ref={ref}
role="alert"
{...rest}
>
{hasIcon && <AlertIcon variation={variation} ariaHidden />}
<View flex="1">
{heading && (
<View className={ComponentClassNames.AlertHeading}>{heading}</View>
)}
<View className={ComponentClassNames.AlertBody}>{children}</View>
</View>
{isDismissible && (
<Button
ariaLabel={dismissButtonLabel}
variation="link"
className={ComponentClassNames.AlertDismiss}
onClick={dismissAlert}
ref={buttonRef}
>
<IconClose aria-hidden="true" />
</Button>
)}
</Flex>
)
);
<View className={ComponentClassNames.AlertBody}>{children}</View>
</View>
{isDismissible && (
<Button
ariaLabel={dismissButtonLabel}
variation="link"
className={ComponentClassNames.AlertDismiss}
onClick={dismissAlert}
ref={buttonRef}
>
<IconClose aria-hidden="true" />
</Button>
)}
</Flex>
) : null;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/primitives/Alert/AlertIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../Icon/internal';

interface AlertIconProps {
variation: AlertVariations;
variation?: AlertVariations;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default variation of Alert and AlertIcon is actually no icon

ariaHidden?: boolean;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/primitives/types/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export interface UseAutocompleteProps extends Partial<AutocompleteProps> {
type SetStateAction<T> = React.Dispatch<React.SetStateAction<T>>;

export interface UseAutocomplete {
activeOptionId: ComboBoxOption['id'];
activeOptionId?: ComboBoxOption['id'];
autocompleteId: string;
composedValue: string;
filteredOptions: ComboBoxOption[];
Expand All @@ -163,7 +163,7 @@ export interface UseAutocomplete {
listboxId: string;
menuId: string;
optionBaseId: string;
setActiveOption: SetStateAction<ComboBoxOption>;
setActiveOption: SetStateAction<ComboBoxOption | null>;
setIsMenuOpen: SetStateAction<boolean>;
setInternalValue: SetStateAction<string>;
}