-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/formatter-fixes
- Loading branch information
Showing
3 changed files
with
72 additions
and
3 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,6 @@ | ||
--- | ||
"@twilio-paste/core": patch | ||
"@twilio-paste/non-modal-dialog-primitive": patch | ||
--- | ||
|
||
[Non-modal Dialog Primitive] Fix to always use a portal when rendering, even when using the state hook. |
49 changes: 49 additions & 0 deletions
49
packages/paste-core/primitives/non-modal-dialog/__tests__/NonModalDialogPrimitive.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { act, fireEvent, render, screen } from "@testing-library/react"; | ||
import * as React from "react"; | ||
|
||
import { | ||
NonModalDialogArrowPrimitive, | ||
NonModalDialogDisclosurePrimitive, | ||
NonModalDialogPrimitive, | ||
type NonModalDialogPrimitivePopoverInitialState, | ||
useNonModalDialogPrimitiveState, | ||
} from "../src"; | ||
|
||
const Example: React.FC<{ options?: NonModalDialogPrimitivePopoverInitialState }> = ({ | ||
options = { placement: "bottom-end" }, | ||
}) => { | ||
const popover = useNonModalDialogPrimitiveState(options); | ||
return ( | ||
<div data-testid="wrapper"> | ||
<NonModalDialogDisclosurePrimitive {...popover}>Open Popover</NonModalDialogDisclosurePrimitive> | ||
<NonModalDialogPrimitive {...popover} aria-label="Welcome"> | ||
<NonModalDialogArrowPrimitive {...popover} /> | ||
Welcome to Reakit! | ||
</NonModalDialogPrimitive> | ||
</div> | ||
); | ||
}; | ||
Example.displayName = "Example"; | ||
|
||
describe("NonModalDialogPrimitive", () => { | ||
describe("portal behavior", () => { | ||
test("renders in a portal under when nothing is provided into hook", async () => { | ||
render(<Example />); | ||
|
||
const wrapper = screen.getByTestId("wrapper"); | ||
const button = screen.getByText("Open Popover"); | ||
const popover = screen.getByText("Welcome to Reakit!"); | ||
expect(wrapper).toBeInTheDocument(); | ||
expect(popover).not.toBeVisible(); | ||
|
||
await act(async () => { | ||
fireEvent.click(button); | ||
}); | ||
|
||
expect(popover).toBeVisible(); | ||
|
||
// Check if popover is in portal | ||
expect(wrapper).not.toContainElement(popover); | ||
}); | ||
}); | ||
}); |
20 changes: 17 additions & 3 deletions
20
packages/paste-core/primitives/non-modal-dialog/src/index.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