Skip to content

Commit b32b395

Browse files
committed
Squashed commit of the following:
commit 0a4821d Author: Adam Thompson <[email protected]> Date: Fri Sep 12 15:34:46 2025 -0400 [LG-5354, LG-5461] fix(Polymorphic) Updates Polymorphic return types (#3111) * PolymorphicRenderFunctionReturnType * propTypes * tsdoc * Create poly-types.md * Update poly-types.md * Create poly-types.md * pkg json scripts * rename PolymorphicReturnType * Update Polymorphic.hooks.tsx * Update Polymorphic.hooks.tsx * rm pre-install step * Adds polymorphic tests to assert event type * fix: Fixes tests failing in React 17 (#3112) * Update r17-packages.json * Update transformToNestedData.spec.ts * Update DrawerToolbarContext.spec.tsx * Update Message.spec.tsx * WIP resizable * Update setup.js * useResizable * Update useScreenReaderAnnouncer.tsx * Update ProgressBar.spec.tsx * changeset * Update .changeset/progress-bar-strict.md * Update react17.yml * Update react17.yml * Update react17.yml * export isReact17 * Update transformToNestedData.spec.ts * Update transformToNestedData.spec.ts * rm cache: false * useDrawerToolbarContext tests * consistent queryByRole
1 parent f61ecfc commit b32b395

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

packages/polymorphic/src/Example/types.spec.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ describe('Typescript types', () => {
126126
<ExamplePolymorphic as={ButtonLikeWrapper} href=".design" />
127127

128128
<ExamplePolymorphic as={AnchorLikeWrapper} href=".design" />
129-
<ExamplePolymorphic as={NextLink} href=".design" />
130129
<ExamplePolymorphic as={() => <></>} />
131130
{/* @ts-expect-error href is not valid on an empty component */}
132131
<ExamplePolymorphic as={() => <></>} href="forbidden"/>
@@ -171,7 +170,6 @@ describe('Typescript types', () => {
171170
<ExamplePolymorphicWithRef as={ButtonLikeWrapper} href=".design" />
172171

173172
<ExamplePolymorphicWithRef as={AnchorLikeWrapper} href=".design" />
174-
<ExamplePolymorphicWithRef as={NextLink} href=".design" />
175173
<ExamplePolymorphicWithRef as={() => <></>} />
176174
{/* @ts-expect-error href is not valid on an empty component */}
177175
<ExamplePolymorphicWithRef as={() => <></>} href="forbidden"/>
@@ -216,7 +214,6 @@ describe('Typescript types', () => {
216214
<AdvancedPolymorphic as={ButtonLikeWrapper} href=".design" />
217215

218216
<AdvancedPolymorphic as={AnchorLikeWrapper} href=".design" />
219-
<AdvancedPolymorphic as={NextLink} href=".design" />
220217
<AdvancedPolymorphic as={() => <></>} />
221218
{/* @ts-expect-error href is not valid on an empty component */}
222219
<AdvancedPolymorphic as={() => <></>} href="forbidden"/>
@@ -261,7 +258,6 @@ describe('Typescript types', () => {
261258
<AdvancedPolymorphicWithRef as={ButtonLikeWrapper} href=".design" />
262259

263260
<AdvancedPolymorphicWithRef as={AnchorLikeWrapper} href=".design" />
264-
<AdvancedPolymorphicWithRef as={NextLink} href=".design" />
265261
<AdvancedPolymorphicWithRef as={() => <></>} />
266262
{/* @ts-expect-error href is not valid on an empty component */}
267263
<AdvancedPolymorphicWithRef as={() => <></>} href="forbidden"/>
@@ -307,9 +303,8 @@ describe('Typescript types', () => {
307303

308304
<ExampleInferred as={AnchorLikeWrapper} href=".design" />
309305

310-
{/** @ts-expect-error TODO: href is not valid on an empty component. See {@link InferredPolymorphicProps} */}
311306
<ExampleInferred as={() => <></>} />
312-
{/** TODO: ts-expect-error href is not valid on an empty component. See {@link InferredPolymorphicProps}*/}
307+
{/** @ts-expect-error href is not valid on an empty component. See {@link InferredPolymorphicProps}*/}
313308
<ExampleInferred as={() => <></>} href="forbidden"/>
314309
</>;
315310
});
@@ -358,9 +353,8 @@ describe('Typescript types', () => {
358353

359354
<ExampleInferredDefaultButton as={AnchorLikeWrapper} href=".design" />
360355

361-
{/** @ts-expect-error TODO: href is not valid on an empty component. See {@link InferredPolymorphicProps} */}
362356
<ExampleInferredDefaultButton as={() => <></>} />
363-
{/** TODO: ts-expect-error href is not valid on an empty component. See {@link InferredPolymorphicProps}*/}
357+
{/** @ts-expect-error href is not valid on an empty component. See {@link InferredPolymorphicProps}*/}
364358
<ExampleInferredDefaultButton as={() => <></>} href="forbidden"/>
365359
</>;
366360
});

packages/polymorphic/src/InferredPolymorphic/InferredPolymorphic.types.spec.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,18 @@ describe.skip('Inferred Polymorphic types', () => {
399399
// @ts-expect-error - href is required
400400
<MyInferredPoly as={'a'} />;
401401
<MyInferredPoly as={'a'} href={'mongodb.design'} />;
402+
403+
// Infers the event argument of onClick callbacks
404+
<MyInferredPoly
405+
as="a"
406+
href={'mongodb.design'}
407+
onClick={event => {
408+
event.preventDefault();
409+
const _El: HTMLAnchorElement = event.currentTarget;
410+
// @ts-expect-error - event.currentTarget is not a button
411+
const _a: HTMLButtonElement = event.currentTarget;
412+
}}
413+
/>;
402414
}
403415

404416
// as = 'button'
@@ -408,6 +420,17 @@ describe.skip('Inferred Polymorphic types', () => {
408420
<MyInferredPoly as="button" href="mongodb.design" />;
409421
// @ts-expect-error misc. props not valid
410422
<MyInferredPoly as="button" foo="bar" />;
423+
424+
// Infers the event argument of onClick callbacks
425+
<MyInferredPoly
426+
as="button"
427+
onClick={event => {
428+
event.preventDefault();
429+
const _El: HTMLButtonElement = event.currentTarget;
430+
// @ts-expect-error - event.currentTarget is not an anchor
431+
const _a: HTMLAnchorElement = event.currentTarget;
432+
}}
433+
/>;
411434
}
412435

413436
// anchor-like

packages/progress-bar/src/ProgressBar/ProgressBar.spec.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,14 @@ describe('packages/progress-bar', () => {
249249
});
250250

251251
test('updates live region text for initial value', () => {
252-
const { queryByRole } = render(
252+
render(
253253
<ProgressBar
254254
value={TEST_VALUE_UNDER_50}
255255
maxValue={TEST_MAX_VALUE}
256256
{...requiredA11yArgs}
257257
/>,
258258
);
259-
const statusElement = queryByRole('status');
259+
const statusElement = screen.queryByRole('status');
260260
const expectedMessage = getAnnouncementMessage(
261261
TEST_VALUE_UNDER_50,
262262
TEST_MAX_VALUE,
@@ -265,14 +265,14 @@ describe('packages/progress-bar', () => {
265265
});
266266

267267
test('ignores further changes until next threshold met', () => {
268-
const { rerender, queryByRole } = render(
268+
const { rerender } = render(
269269
<ProgressBar
270270
value={TEST_VALUE_UNDER_50}
271271
maxValue={TEST_MAX_VALUE}
272272
{...requiredA11yArgs}
273273
/>,
274274
);
275-
const statusElement = queryByRole('status');
275+
const statusElement = screen.queryByRole('status');
276276
const expectedMessage = getAnnouncementMessage(
277277
TEST_VALUE_UNDER_50,
278278
TEST_MAX_VALUE,
@@ -292,14 +292,14 @@ describe('packages/progress-bar', () => {
292292
});
293293

294294
test('updates live region text if 50% threshold passed', async () => {
295-
const { getByRole, rerender } = render(
295+
const { rerender } = render(
296296
<ProgressBar
297297
value={TEST_VALUE_UNDER_50}
298298
maxValue={TEST_MAX_VALUE}
299299
{...requiredA11yArgs}
300300
/>,
301301
);
302-
const statusElement = getByRole('status');
302+
const statusElement = screen.getByRole('status');
303303

304304
expect(statusElement).toBeInTheDocument();
305305
expect(statusElement).toHaveTextContent(

0 commit comments

Comments
 (0)