Skip to content

Commit

Permalink
Merge pull request #5301 from qburst/upgrade/react-19
Browse files Browse the repository at this point in the history
🚨 Fix TypeScript Linting warnings for React 19 upgrade
  • Loading branch information
martijnrusschen authored Jan 6, 2025
2 parents 9de10cd + cb56f57 commit 011c335
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
}
}

containerRef: React.RefObject<HTMLDivElement>;
containerRef: React.RefObject<HTMLDivElement | null>;

monthContainer: CalendarState["monthContainer"] = undefined;

Expand Down
13 changes: 9 additions & 4 deletions src/calendar_icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ const CalendarIcon: React.FC<CalendarIconProps> = ({

if (React.isValidElement(icon)) {
// Because we are checking that typeof icon is string first, we can safely cast icon as React.ReactElement on types level and code level
return React.cloneElement(icon as React.ReactElement, {
className: `${icon.props.className || ""} ${defaultClass} ${className}`,
const iconElement = icon as React.ReactElement<{
className: string;
onClick: (event: React.MouseEvent) => void;
}>;

return React.cloneElement(iconElement, {
className: `${iconElement.props.className || ""} ${defaultClass} ${className}`,
onClick: (event: React.MouseEvent) => {
if (typeof icon.props.onClick === "function") {
icon.props.onClick(event);
if (typeof iconElement.props.onClick === "function") {
iconElement.props.onClick(event);
}

if (typeof onClick === "function") {
Expand Down
8 changes: 6 additions & 2 deletions src/input_time.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ interface InputTimeProps {
date?: Date;
timeString?: string;
timeInputLabel?: string;
customTimeInput?: React.ReactElement;
customTimeInput?: React.ReactElement<{
date?: Date;
value: string;
onChange: (time: string) => void;
}>;
}

interface InputTimeState {
Expand All @@ -32,7 +36,7 @@ export default class InputTime extends Component<
InputTimeProps,
InputTimeState
> {
inputRef: React.RefObject<HTMLInputElement> = React.createRef();
inputRef: React.RefObject<HTMLInputElement | null> = React.createRef();

constructor(props: InputTimeProps) {
super(props);
Expand Down
2 changes: 1 addition & 1 deletion src/tab_loop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class TabLoop extends Component<TabLoopProps> {
this.tabLoopRef = createRef();
}

private tabLoopRef: React.RefObject<HTMLDivElement>;
private tabLoopRef: React.RefObject<HTMLDivElement | null>;

/**
* `getTabChildren` is a method of the `TabLoop` class that retrieves all tabbable children of the component.
Expand Down
2 changes: 1 addition & 1 deletion src/with_floating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function withFloating<T extends FloatingProps>(
const WithFloating: React.FC<R> = (props): React.ReactElement => {
const hidePopper: boolean =
typeof props.hidePopper === "boolean" ? props.hidePopper : true;
const arrowRef: React.RefObject<HTMLElement> = useRef(null);
const arrowRef: React.RefObject<HTMLElement | null> = useRef(null);
const floatingProps = useFloating({
open: !hidePopper,
whileElementsMounted: autoUpdate,
Expand Down
2 changes: 1 addition & 1 deletion src/year_dropdown_options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class YearDropdownOptions extends Component<
}
}

dropdownRef: React.RefObject<HTMLDivElement>;
dropdownRef: React.RefObject<HTMLDivElement | null>;

renderOptions = (): React.ReactElement[] => {
const selectedYear = this.props.year;
Expand Down

0 comments on commit 011c335

Please sign in to comment.