Skip to content

Commit 8d844a1

Browse files
authored
chore: Fix useBaseComponent types (#3742)
1 parent fa5bdbd commit 8d844a1

File tree

40 files changed

+78
-72
lines changed

40 files changed

+78
-72
lines changed

src/alert/index.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33
'use client';
4-
import React, { useEffect } from 'react';
4+
import React, { useEffect, useRef } from 'react';
55

6-
import { useUniqueId } from '@cloudscape-design/component-toolkit/internal';
6+
import { useMergeRefs, useUniqueId } from '@cloudscape-design/component-toolkit/internal';
77
import { getAnalyticsMetadataAttribute } from '@cloudscape-design/component-toolkit/internal/analytics-metadata';
88

99
import { FunnelMetrics } from '../internal/analytics';
@@ -23,13 +23,16 @@ export { AlertProps };
2323
const Alert = React.forwardRef(
2424
({ type = 'info', visible = true, style, ...props }: AlertProps, ref: React.Ref<AlertProps.Ref>) => {
2525
const analyticsMetadata = getAnalyticsMetadataProps(props as BasePropsWithAnalyticsMetadata);
26-
const baseComponentProps = useBaseComponent<HTMLDivElement>(
26+
27+
const baseComponentProps = useBaseComponent(
2728
'Alert',
2829
{
2930
props: { type, visible, dismissible: props.dismissible },
3031
},
3132
analyticsMetadata
3233
);
34+
const rootRef = useRef<HTMLElement>(null);
35+
const __internalRootRef = useMergeRefs(rootRef, baseComponentProps.__internalRootRef);
3336

3437
const { funnelIdentifier, funnelInteractionId, funnelErrorContext, submissionAttempt, funnelState, errorCount } =
3538
useFunnel();
@@ -47,7 +50,7 @@ const Alert = React.forwardRef(
4750
errorCount.current++;
4851

4952
// We don't want to report an error if it is hidden, e.g. inside an Expandable Section.
50-
const errorIsVisible = (baseComponentProps.__internalRootRef.current?.getBoundingClientRect()?.width ?? 0) > 0;
53+
const errorIsVisible = (rootRef.current?.getBoundingClientRect()?.width ?? 0) > 0;
5154

5255
if (errorIsVisible) {
5356
if (subStepSelector) {
@@ -72,7 +75,7 @@ const Alert = React.forwardRef(
7275
stepNameSelector,
7376
stepName,
7477
stepIdentifier,
75-
currentDocument: baseComponentProps.__internalRootRef.current?.ownerDocument,
78+
currentDocument: rootRef.current?.ownerDocument,
7679
totalSubSteps: subStepCount.current,
7780
funnelIdentifier,
7881
subStepAllSelector: getSubStepAllSelector(),
@@ -112,6 +115,7 @@ const Alert = React.forwardRef(
112115
visible={visible}
113116
{...props}
114117
{...baseComponentProps}
118+
__internalRootRef={__internalRootRef}
115119
ref={ref}
116120
messageSlotId={messageSlotId}
117121
style={style}

src/alert/internal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const typeToIcon: Record<AlertProps.Type, IconProps['name']> = {
3838
};
3939

4040
type InternalAlertProps = SomeRequired<AlertProps, 'type'> &
41-
InternalBaseComponentProps<HTMLDivElement> & {
41+
InternalBaseComponentProps & {
4242
messageSlotId?: string;
4343
style?: AlertProps['style'];
4444
};
@@ -59,7 +59,7 @@ const InternalAlert = React.forwardRef(
5959
action,
6060
onDismiss,
6161
onButtonClick,
62-
__internalRootRef = null,
62+
__internalRootRef,
6363
statusIconAriaLabel: deprecatedStatusIconAriaLabel,
6464
dismissAriaLabel: deprecatedDismissAriaLabel,
6565
messageSlotId,

src/anchor-navigation/internal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default function InternalAnchorNavigation({
1919
onFollow,
2020
onActiveHrefChange,
2121
activeHref = '',
22-
__internalRootRef = null,
22+
__internalRootRef,
2323
scrollSpyOffset = 0,
2424
...props
2525
}: AnchorNavigationProps & InternalBaseComponentProps) {

src/app-layout-toolbar/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const AppLayoutToolbar = React.forwardRef(
5454
);
5555
}
5656
}
57-
const { __internalRootRef } = useBaseComponent<HTMLDivElement>(
57+
const { __internalRootRef } = useBaseComponent(
5858
'AppLayoutToolbar',
5959
{
6060
props: {

src/app-layout/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const AppLayout = React.forwardRef(
4646
);
4747
}
4848
}
49-
const { __internalRootRef } = useBaseComponent<HTMLDivElement>(
49+
const { __internalRootRef } = useBaseComponent(
5050
'AppLayout',
5151
{
5252
props: {

src/area-chart/internal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default function InternalAreaChart<T extends AreaChartProps.DataTypes>({
6464
loadingText,
6565
recoveryText,
6666
onRecoveryClick,
67-
__internalRootRef = null,
67+
__internalRootRef,
6868
...props
6969
}: InternalAreaChartProps<T>) {
7070
const baseProps = getBaseProps(props);

src/attribute-editor/internal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const InternalAttributeEditor = React.forwardRef(
4343
i18nStrings,
4444
onAddButtonClick,
4545
onRemoveButtonClick,
46-
__internalRootRef = null,
46+
__internalRootRef,
4747
...props
4848
}: InternalAttributeEditorProps<T>,
4949
ref: React.Ref<AttributeEditorProps.Ref>

src/box/internal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function InternalBox({
2323
fontWeight,
2424
color,
2525
children,
26-
__internalRootRef = null,
26+
__internalRootRef,
2727
...props
2828
}: InternalBoxProps) {
2929
const baseProps = getBaseProps(props);

src/button-group/internal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const InternalButtonGroup = forwardRef(
3030
onFilesChange,
3131
ariaLabel,
3232
dropdownExpandToViewport,
33-
__internalRootRef = null,
33+
__internalRootRef,
3434
...props
3535
}: InternalButtonGroupProps,
3636
ref: React.Ref<ButtonGroupProps.Ref>

src/button/internal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export type InternalButtonProps = Omit<ButtonProps, 'variant'> & {
5656
__title?: string;
5757
__emitPerformanceMarks?: boolean;
5858
__skipNativeAttributesWarnings?: boolean;
59-
} & InternalBaseComponentProps<HTMLAnchorElement | HTMLButtonElement>;
59+
} & InternalBaseComponentProps;
6060

6161
export const InternalButton = React.forwardRef(
6262
(
@@ -92,7 +92,7 @@ export const InternalButton = React.forwardRef(
9292
style,
9393
nativeButtonAttributes,
9494
nativeAnchorAttributes,
95-
__internalRootRef = null,
95+
__internalRootRef,
9696
__focusable = false,
9797
__injectAnalyticsComponentMetadata = false,
9898
__title,

0 commit comments

Comments
 (0)