Skip to content

Commit ae2a39c

Browse files
Add container prop to ToastProvider (#1692)
<!-- How to write a good PR title: - Follow [the Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/). - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ## Self Checklist - [x] I wrote a PR title in **English** and added an appropriate **label** to the PR. - [x] I wrote the commit message in **English** and to follow [**the Conventional Commits specification**](https://www.conventionalcommits.org/en/v1.0.0/). - [x] I [added the **changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md) about the changes that needed to be released. (or didn't have to) - [x] I wrote or updated **documentation** related to the changes. (or didn't have to) - [x] I wrote or updated **tests** related to the changes. (or didn't have to) - [x] I tested the changes in various browsers. (or didn't have to) - Windows: Chrome, Edge, (Optional) Firefox - macOS: Chrome, Edge, Safari, (Optional) Firefox ## Related Issue <!-- Please link to issue if one exists --> <!-- Fixes #0000 --> Fixes #1689 ## Summary <!-- Please brief explanation of the changes made --> ToastProvider에서 container(givenContainer)를 주입바다 portal target으로 사용하도록 지정합니다 Overlay에서 사용하는 컨벤션을 그대로 적용합니다 ## Details <!-- Please elaborate description of the changes --> window.open과 react.portal을 사용해 팝업창에서 React를 구동하고자 하는 니즈가 있습니다 이에 ToastProvider를 새 창에 렌더해야하고, 이 때 js context상에서는 기존 window 객체에만 접근할 수 있기에 기존 ToastProvider에서는 새 window 객체에 접근할 수 없고, 따라서 새 창에 portal을 만들 수 없었습니다 이에 prop을 추가하여 portal target container를 지정할 수 있도록 합니다 지정하지 않는다면 기존처럼 fallback(getRootElement())에 붙습니다 ### Breaking change? (Yes/No) <!-- If Yes, please describe the impact and migration path for users --> No. 신규 Props가 추가되었으며 기존 동작 및 코드에는 영향이 가지 않습니다 --------- Co-authored-by: Ed <sungik.dev@gmail.com>
1 parent b42e38f commit ae2a39c

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

.changeset/shiny-walls-kick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@channel.io/bezier-react": minor
3+
---
4+
5+
Add container prop to ToastProvider

packages/bezier-react/src/components/Toast/Toast.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export default interface ToastElementProps extends
7575

7676
export interface ToastProviderProps {
7777
autoDismissTimeout?: number
78+
container?: HTMLElement | null
7879
children?: ReactNode[] | ReactNode
7980
}
8081

packages/bezier-react/src/components/Toast/ToastProvider.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import useToastProviderValues from './useToastContextValues'
2323

2424
function ToastProvider({
2525
autoDismissTimeout = 3000,
26+
container: givenContainer,
2627
children = [],
2728
}: ToastProviderProps) {
2829
const isMounted = useIsMounted()
@@ -33,6 +34,7 @@ function ToastProvider({
3334
rightToasts,
3435
dismiss,
3536
} = toastContextValue
37+
const container = givenContainer ?? getRootElement()
3638

3739
const createContainer = useCallback((placement: ToastPlacement, toasts: ToastType[]) => (
3840
<ToastContainer
@@ -85,7 +87,7 @@ function ToastProvider({
8587
createContainer(ToastPlacement.BottomLeft, leftToasts),
8688
createContainer(ToastPlacement.BottomRight, rightToasts),
8789
],
88-
getRootElement(),
90+
container,
8991
) }
9092
</ToastContextProvider>
9193
)

0 commit comments

Comments
 (0)