-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: TypeError: Cannot read properties of undefined (reading '0') in …
…datagrid (#4724) * Stop propagate on click radio group events * Add changeset * Refactor RadioGroup * Add radix issue
- Loading branch information
Showing
6 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": patch | ||
--- | ||
|
||
Fix "TypeError: Cannot read properties of undefined (reading '0')" error thrown by datagrid by stop propagating events from RadioGroup component in ChannelsAvailability. RadioGroup fires couple events at onec and datagrid listing to global onClick event, that cause error in datagrid. |
9 changes: 2 additions & 7 deletions
9
src/components/ChannelsAvailabilityCard/Channel/ChannelAvailabilityItemContent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
RadioGroup as RadioGroupBase, | ||
RadioGroupRootProps, | ||
} from "@saleor/macaw-ui-next"; | ||
import React from "react"; | ||
|
||
import { StopPropagation } from "../StopPropagation"; | ||
|
||
const RadioGroupRoot = (props: RadioGroupRootProps) => { | ||
// StopProgation is used here to block onClick events from RadioGroup that cause throw error in datagrid | ||
// Datagrid listing for all on click event but RadioGroup emitated couple events at onced | ||
// Radix issue: https://github.com/radix-ui/primitives/issues/1982 | ||
return ( | ||
<StopPropagation> | ||
<RadioGroupBase {...props} /> | ||
</StopPropagation> | ||
); | ||
}; | ||
|
||
export const RadioGroup = Object.assign(RadioGroupRoot, { | ||
Item: RadioGroupBase.Item, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./RadioGroup"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React, { ReactNode } from "react"; | ||
|
||
interface StopPropagationProps { | ||
children: ReactNode; | ||
} | ||
|
||
// If you don't want to click events bubble in the DOM tree, you can use this component. | ||
export const StopPropagation = ({ children }: StopPropagationProps) => { | ||
const stopPropagation = (e: React.MouseEvent) => e.stopPropagation(); | ||
|
||
return <div onClick={stopPropagation}>{children}</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./StopPropagation"; |