Skip to content
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
4 changes: 2 additions & 2 deletions packages/ariakit/src/badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

import { assertEmpty, mergeCSSClasses } from "@blocknote/core";
import { ComponentProps } from "@blocknote/react";
import { forwardRef } from "react";
import { type MouseEvent, forwardRef } from "react";

export const Badge = forwardRef<
HTMLButtonElement,
Expand Down Expand Up @@ -36,7 +36,7 @@ export const Badge = forwardRef<
isSelected && "bn-ak-primary",
)}
aria-selected={isSelected === true}
onClick={(event) => onClick?.(event)}
onClick={(event: MouseEvent<HTMLButtonElement>) => onClick?.(event)}
onMouseEnter={onMouseEnter}
ref={ref}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/ariakit/src/panel/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Panel = forwardRef<
<AriakitTabProvider
defaultSelectedId={defaultOpenTab}
selectedId={openTab}
setActiveId={(activeId) => {
setActiveId={(activeId: string | null | undefined) => {
if (activeId) {
setOpenTab(activeId);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ariakit/src/panel/PanelFileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {

import { assertEmpty } from "@blocknote/core";
import { ComponentProps } from "@blocknote/react";
import { forwardRef } from "react";
import { forwardRef, type ChangeEvent } from "react";

export const PanelFileInput = forwardRef<
HTMLInputElement,
Expand All @@ -24,7 +24,7 @@ export const PanelFileInput = forwardRef<
type={"file"}
accept={accept}
value={value ? value.name : undefined}
onChange={async (e) => onChange?.(e.target.files![0])}
onChange={async (e: ChangeEvent<HTMLInputElement>) => onChange?.(e.target.files![0])}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard nullable files before indexing.

e.target.files! can be null on some input states, which can throw at runtime when [0] is accessed.

Proposed fix
-        onChange={async (e: ChangeEvent<HTMLInputElement>) => onChange?.(e.target.files![0])}
+        onChange={async (e: ChangeEvent<HTMLInputElement>) => {
+          const file = e.target.files?.[0];
+          if (file) {
+            onChange?.(file);
+          }
+        }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onChange={async (e: ChangeEvent<HTMLInputElement>) => onChange?.(e.target.files![0])}
onChange={async (e: ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (file) {
onChange?.(file);
}
}}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ariakit/src/panel/PanelFileInput.tsx` at line 27, The onChange
handler in PanelFileInput blindly accesses e.target.files![0], which can be null
and throw; update the handler in the PanelFileInput component to guard the
nullable files before indexing (e.g., check e.target.files and files.length or
use optional chaining like e.target.files?.[0]) and only call onChange?.(...)
when a File exists, otherwise do nothing or pass undefined as intended.

placeholder={placeholder}
/>
</AriakitFormProvider>
Expand Down
4 changes: 2 additions & 2 deletions packages/ariakit/src/toolbar/ToolbarButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {

import { assertEmpty, isSafari, mergeCSSClasses } from "@blocknote/core";
import { ComponentProps } from "@blocknote/react";
import { forwardRef } from "react";
import { forwardRef, type MouseEvent } from "react";

type ToolbarButtonProps = ComponentProps["Generic"]["Toolbar"]["Button"];

Expand Down Expand Up @@ -46,7 +46,7 @@ export const ToolbarButton = forwardRef<HTMLButtonElement, ToolbarButtonProps>(
)}
// Needed as Safari doesn't focus button elements on mouse down
// unlike other browsers.
onMouseDown={(e) => {
onMouseDown={(e: MouseEvent<HTMLButtonElement>) => {
if (isSafari()) {
(e.currentTarget as HTMLButtonElement).focus();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/xl-ai/src/components/AIMenu/AIMenuController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const AIMenuController = (props: {
// We should just be able to set `referencePress: true` instead of
// using this listener, but this doesn't seem to trigger.
// (probably because we don't assign the referenceProps to the reference element)
outsidePress: (event) => {
outsidePress: (event: MouseEvent) => {
if (event.target instanceof Element) {
const blockElement = event.target.closest(".bn-block");
if (
Expand Down
Loading