This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Niloofar / Dropdown implementations #12
Merged
matin-deriv
merged 3 commits into
deriv-com:main
from
niloofar-deriv:niloo/86bw351qv/dropdown
Oct 20, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
10 changes: 9 additions & 1 deletion
10
src/components/ui/dialog/dialog.test.tsx → ...onents/ui/dialog/__test__/dialog.test.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
98 changes: 98 additions & 0 deletions
98
src/components/ui/dropdown-menu/__test__/dropdown-menu.test.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,98 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuTrigger, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuLabel, | ||
DropdownMenuSeparator, | ||
} from '../index'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
describe('Dropdown component', () => { | ||
it('Should render the dropdown component', () => { | ||
render( | ||
<DropdownMenu> | ||
<p>This is a test children</p> | ||
</DropdownMenu> | ||
); | ||
expect(screen.getByText('This is a test children')).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should open the dropdown when the Trigger is clicked', async () => { | ||
render( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger>Trigger</DropdownMenuTrigger> | ||
<DropdownMenuContent> | ||
<DropdownMenuItem>item</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
|
||
await userEvent.click(screen.getByText('Trigger')); | ||
expect(screen.getByText('item')).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should render the dropdown with the passed classNames', async () => { | ||
render( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger className='bg-red'>Trigger</DropdownMenuTrigger> | ||
<DropdownMenuContent> | ||
<DropdownMenuItem className='m-1'>item</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
|
||
const trigger_button = screen.getByText('Trigger'); | ||
expect(trigger_button).toHaveClass('bg-red'); | ||
await userEvent.click(trigger_button); | ||
expect(screen.getByText('item')).toHaveClass('m-1'); | ||
}); | ||
|
||
it("Should render the content's label", async () => { | ||
render( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger>Trigger</DropdownMenuTrigger> | ||
<DropdownMenuContent> | ||
<DropdownMenuLabel>Test Label</DropdownMenuLabel> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
|
||
await userEvent.click(screen.getByText('Trigger')); | ||
expect(screen.getByText('Test Label')).toBeInTheDocument(); | ||
}); | ||
|
||
it('Should close the dropdown when an item clicked', async () => { | ||
render( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger>Trigger</DropdownMenuTrigger> | ||
<DropdownMenuContent> | ||
<DropdownMenuItem>item</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
|
||
await userEvent.click(screen.getByText('Trigger')); | ||
const dropdown_item = screen.getByText('item'); | ||
await userEvent.click(dropdown_item); | ||
expect(dropdown_item).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('Should show the dropdown menu separator', async () => { | ||
render( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger>Trigger</DropdownMenuTrigger> | ||
<DropdownMenuContent> | ||
<DropdownMenuLabel>Test Label</DropdownMenuLabel> | ||
<DropdownMenuSeparator data-testid='dt_dropdown_menu_separator' /> | ||
<DropdownMenuItem>item</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
|
||
await userEvent.click(screen.getByText('Trigger')); | ||
expect(screen.getByTestId('dt_dropdown_menu_separator')).toBeInTheDocument(); | ||
matin-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); |
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,69 @@ | ||
import { forwardRef, ElementRef, ComponentPropsWithoutRef } from 'react'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Auto generated component |
||
import { | ||
Root, | ||
Trigger, | ||
Portal, | ||
Sub, | ||
SubTrigger, | ||
SubContent, | ||
Content, | ||
Item, | ||
Label, | ||
Separator, | ||
} from '@radix-ui/react-dropdown-menu'; | ||
|
||
const DropdownMenu = Root; | ||
const DropdownMenuTrigger = Trigger; | ||
const DropdownMenuPortal = Portal; | ||
const DropdownMenuSub = Sub; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we don't have a common drop-down style I removed all of the classnames, later when we want to use this we can pass the classes to it! |
||
const DropdownMenuSubTrigger = forwardRef<ElementRef<typeof SubTrigger>, ComponentPropsWithoutRef<typeof SubTrigger>>( | ||
({ children, ...props }, ref) => ( | ||
<SubTrigger ref={ref} {...props}> | ||
{children} | ||
</SubTrigger> | ||
) | ||
); | ||
DropdownMenuSubTrigger.displayName = SubTrigger.displayName; | ||
|
||
const DropdownMenuSubContent = forwardRef<ElementRef<typeof SubContent>, ComponentPropsWithoutRef<typeof SubContent>>( | ||
(props, ref) => <SubContent ref={ref} {...props} /> | ||
); | ||
DropdownMenuSubContent.displayName = SubContent.displayName; | ||
|
||
const DropdownMenuContent = forwardRef<ElementRef<typeof Content>, ComponentPropsWithoutRef<typeof Content>>( | ||
({ sideOffset = 4, ...props }, ref) => ( | ||
<Portal> | ||
<Content ref={ref} sideOffset={sideOffset} {...props} /> | ||
</Portal> | ||
) | ||
); | ||
DropdownMenuContent.displayName = Content.displayName; | ||
|
||
const DropdownMenuItem = forwardRef<ElementRef<typeof Item>, ComponentPropsWithoutRef<typeof Item>>((props, ref) => ( | ||
<Item ref={ref} {...props} /> | ||
)); | ||
DropdownMenuItem.displayName = Item.displayName; | ||
|
||
const DropdownMenuLabel = forwardRef<ElementRef<typeof Label>, ComponentPropsWithoutRef<typeof Label>>((props, ref) => ( | ||
<Label ref={ref} {...props} /> | ||
)); | ||
DropdownMenuLabel.displayName = Label.displayName; | ||
|
||
const DropdownMenuSeparator = forwardRef<ElementRef<typeof Separator>, ComponentPropsWithoutRef<typeof Separator>>( | ||
(props, ref) => <Separator ref={ref} {...props} /> | ||
); | ||
DropdownMenuSeparator.displayName = Separator.displayName; | ||
|
||
export { | ||
DropdownMenu, | ||
DropdownMenuTrigger, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuLabel, | ||
DropdownMenuSeparator, | ||
DropdownMenuPortal, | ||
DropdownMenuSub, | ||
DropdownMenuSubContent, | ||
DropdownMenuSubTrigger, | ||
}; |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the test file to the
__test__
folder!