Skip to content

Commit 2dd87e0

Browse files
authored
fix: update types and address todos (#18747)
1 parent a9a204a commit 2dd87e0

File tree

13 files changed

+78
-59
lines changed

13 files changed

+78
-59
lines changed

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4948,7 +4948,23 @@ Map {
49484948
"args": Array [
49494949
Object {
49504950
"current": Object {
4951-
"type": "any",
4951+
"args": Array [
4952+
Array [
4953+
Object {
4954+
"type": "any",
4955+
},
4956+
Object {
4957+
"args": Array [
4958+
Array [
4959+
null,
4960+
],
4961+
],
4962+
"type": "oneOf",
4963+
},
4964+
],
4965+
],
4966+
"isRequired": true,
4967+
"type": "oneOfType",
49524968
},
49534969
},
49544970
],

packages/react/src/components/InlineLoading/InlineLoading.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ const InlineLoading = ({
124124
return undefined;
125125
};
126126

127-
// TODO: Should this element only be constructed, similar to
128-
// `loadingAnimation`, if `description` is specified?
129-
const loadingText = (
127+
const loadingText = description && (
130128
<div className={`${prefix}--inline-loading__text`}>{description}</div>
131129
);
132130
const loading = getLoading();
@@ -139,7 +137,7 @@ const InlineLoading = ({
139137
{...rest}
140138
aria-live={rest['aria-live'] ?? 'assertive'}>
141139
{loadingAnimation}
142-
{description && loadingText}
140+
{loadingText}
143141
</div>
144142
);
145143
};

packages/react/src/components/Modal/Modal.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
/**
2-
* Copyright IBM Corp. 2016, 2023
2+
* Copyright IBM Corp. 2016, 2025
33
*
44
* This source code is licensed under the Apache-2.0 license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import PropTypes from 'prop-types';
9-
import React, { useRef, useEffect, useState, ReactNode } from 'react';
8+
import PropTypes, { type Validator } from 'prop-types';
9+
import React, {
10+
useEffect,
11+
useRef,
12+
useState,
13+
type ReactNode,
14+
type Ref,
15+
} from 'react';
1016
import classNames from 'classnames';
1117
import { Close } from '@carbon/icons-react';
1218
import toggleClass from '../../tools/toggleClass';
@@ -98,7 +104,7 @@ export interface ModalProps extends ReactAttr<HTMLDivElement> {
98104
/**
99105
* Provide a ref to return focus to once the modal is closed.
100106
*/
101-
launcherButtonRef?: any; // TODO FIXME
107+
launcherButtonRef?: Ref<HTMLButtonElement>;
102108

103109
/**
104110
* Specify the description for the loading text
@@ -426,7 +432,9 @@ const Modal = React.forwardRef(function Modal(
426432
useEffect(() => {
427433
if (!open && launcherButtonRef) {
428434
setTimeout(() => {
429-
launcherButtonRef?.current?.focus();
435+
if ('current' in launcherButtonRef) {
436+
launcherButtonRef.current?.focus();
437+
}
430438
});
431439
}
432440
}, [open, launcherButtonRef]);
@@ -701,9 +709,17 @@ Modal.propTypes = {
701709
launcherButtonRef: PropTypes.oneOfType([
702710
PropTypes.func,
703711
PropTypes.shape({
704-
current: PropTypes.any,
712+
current: PropTypes.oneOfType([
713+
// `PropTypes.instanceOf(HTMLButtonElement)` alone won't work because
714+
// `HTMLButtonElement` is not defined in the test environment even
715+
// though `testEnvironment` is set to `jsdom`.
716+
typeof HTMLButtonElement !== 'undefined'
717+
? PropTypes.instanceOf(HTMLButtonElement)
718+
: PropTypes.any,
719+
PropTypes.oneOf([null]),
720+
]).isRequired,
705721
}),
706-
]),
722+
]) as Validator<Ref<HTMLButtonElement>>,
707723

708724
/**
709725
* Specify the description for the loading text

packages/react/src/components/Modal/next/index.tsx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright IBM Corp. 2016, 2023
2+
* Copyright IBM Corp. 2016, 2025
33
*
44
* This source code is licensed under the Apache-2.0 license found in the
55
* LICENSE file in the root directory of this source tree.
@@ -82,11 +82,6 @@ export interface BaseModalProps extends ReactAttr<HTMLDivElement> {
8282
*/
8383
isFullWidth?: boolean;
8484

85-
/**
86-
* Provide a ref to return focus to once the modal is closed.
87-
*/
88-
launcherButtonRef?: any; // TODO FIXME
89-
9085
/**
9186
* Specify the description for the loading text
9287
*/
@@ -260,7 +255,6 @@ const Modal = React.forwardRef(function Modal(
260255
closeButtonLabel = 'Close',
261256
preventCloseOnClickOutside = false,
262257
isFullWidth,
263-
launcherButtonRef,
264258
loadingStatus = 'inactive',
265259
loadingDescription,
266260
loadingIconDescription,
@@ -549,16 +543,6 @@ Modal.propTypes = {
549543
*/
550544
isFullWidth: PropTypes.bool,
551545

552-
/**
553-
* Provide a ref to return focus to once the modal is closed.
554-
*/
555-
launcherButtonRef: PropTypes.oneOfType([
556-
PropTypes.func,
557-
PropTypes.shape({
558-
current: PropTypes.any,
559-
}),
560-
]),
561-
562546
/**
563547
* Specify the description for the loading text
564548
*/

packages/react/src/components/Tile/Tile.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* Copyright IBM Corp. 2019, 2025
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
18
import React, {
29
useEffect,
310
useRef,
@@ -488,8 +495,7 @@ export const SelectableTile = React.forwardRef<
488495
className
489496
);
490497

491-
// TODO: rename to handleClick when handleClick prop is deprecated
492-
function handleOnClick(evt) {
498+
function handleClick(evt) {
493499
evt.preventDefault();
494500
evt?.persist?.();
495501
if (
@@ -504,8 +510,7 @@ export const SelectableTile = React.forwardRef<
504510
onChange(evt, isSelected, id);
505511
}
506512

507-
// TODO: rename to handleKeyDown when handleKeyDown prop is deprecated
508-
function handleOnKeyDown(evt) {
513+
function handleKeyDown(evt) {
509514
evt?.persist?.();
510515
if (matches(evt, [keys.Enter, keys.Space])) {
511516
evt.preventDefault();
@@ -547,10 +552,10 @@ export const SelectableTile = React.forwardRef<
547552
// eslint-disable-next-line jsx-a11y/interactive-supports-focus
548553
<div
549554
className={classes}
550-
onClick={!disabled ? handleOnClick : undefined}
555+
onClick={!disabled ? handleClick : undefined}
551556
role="checkbox"
552557
aria-checked={isSelected}
553-
onKeyDown={!disabled ? handleOnKeyDown : undefined}
558+
onKeyDown={!disabled ? handleKeyDown : undefined}
554559
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
555560
tabIndex={!disabled ? tabIndex : undefined}
556561
ref={ref}

packages/web-components/src/components/checkbox/checkbox.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license
33
*
4-
* Copyright IBM Corp. 2019, 2023
4+
* Copyright IBM Corp. 2019, 2025
55
*
66
* This source code is licensed under the Apache-2.0 license found in the
77
* LICENSE file in the root directory of this source tree.
@@ -61,8 +61,8 @@ class CDSCheckbox extends FocusMixin(FormMixin(LitElement)) {
6161
}
6262
}
6363

64-
_handleFormdata(event: Event) {
65-
const { formData } = event as any; // TODO: Wait for `FormDataEvent` being available in `lib.dom.d.ts`
64+
_handleFormdata(event: FormDataEvent) {
65+
const { formData } = event;
6666
const { checked, disabled, name, value = 'on' } = this;
6767
if (!disabled && checked) {
6868
formData.append(name, value);

packages/web-components/src/components/date-picker/date-picker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license
33
*
4-
* Copyright IBM Corp. 2019, 2024
4+
* Copyright IBM Corp. 2019, 2025
55
*
66
* This source code is licensed under the Apache-2.0 license found in the
77
* LICENSE file in the root directory of this source tree.
@@ -227,8 +227,8 @@ class CDSDatePicker extends HostListenerMixin(FormMixin(LitElement)) {
227227
.join('/');
228228
};
229229

230-
_handleFormdata(event: Event) {
231-
const { formData } = event as any; // TODO: Wait for `FormDataEvent` being available in `lib.dom.d.ts`
230+
_handleFormdata(event: FormDataEvent) {
231+
const { formData } = event;
232232
const { disabled, name, value } = this;
233233
if (!disabled) {
234234
formData.append(name, value);

packages/web-components/src/components/dropdown/dropdown.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license
33
*
4-
* Copyright IBM Corp. 2019, 2024
4+
* Copyright IBM Corp. 2019, 2025
55
*
66
* This source code is licensed under the Apache-2.0 license found in the
77
* LICENSE file in the root directory of this source tree.
@@ -466,8 +466,8 @@ class CDSDropdown extends ValidityMixin(
466466
*
467467
* @param event The event.
468468
*/
469-
_handleFormdata(event: Event) {
470-
const { formData } = event as any; // TODO: Wait for `FormDataEvent` being available in `lib.dom.d.ts`
469+
_handleFormdata(event: FormDataEvent) {
470+
const { formData } = event;
471471
const { disabled, name, value } = this;
472472
if (!disabled) {
473473
formData.append(name, value);

packages/web-components/src/components/radio-button/radio-button-group.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license
33
*
4-
* Copyright IBM Corp. 2019, 2024
4+
* Copyright IBM Corp. 2019, 2025
55
*
66
* This source code is licensed under the Apache-2.0 license found in the
77
* LICENSE file in the root directory of this source tree.
@@ -62,8 +62,8 @@ class CDSRadioButtonGroup extends FormMixin(HostListenerMixin(LitElement)) {
6262
}
6363
};
6464

65-
_handleFormdata(event: Event) {
66-
const { formData } = event as any; // TODO: Wait for `FormDataEvent` being available in `lib.dom.d.ts`
65+
_handleFormdata(event: FormDataEvent) {
66+
const { formData } = event;
6767
const { disabled, name, value } = this;
6868
if (
6969
!disabled &&

packages/web-components/src/components/search/search.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license
33
*
4-
* Copyright IBM Corp. 2019, 2023
4+
* Copyright IBM Corp. 2019, 2025
55
*
66
* This source code is licensed under the Apache-2.0 license found in the
77
* LICENSE file in the root directory of this source tree.
@@ -113,8 +113,8 @@ class CDSSearch extends HostListenerMixin(FocusMixin(FormMixin(LitElement))) {
113113
this.hasCustomIcon = true;
114114
}
115115

116-
_handleFormdata(event: Event) {
117-
const { formData } = event as any; // TODO: Wait for `FormDataEvent` being available in `lib.dom.d.ts`
116+
_handleFormdata(event: FormDataEvent) {
117+
const { formData } = event;
118118
const { disabled, name, value } = this;
119119
if (!disabled) {
120120
formData.append(name, value);

0 commit comments

Comments
 (0)