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
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { Dialog, Modal } from './modal';

describe('Modal theme roles', () => {
it('renders the dialog panel on the overlay surface with overlay elevation', () => {
render(
<Modal isOpen>
<Dialog title="Settings">
<Dialog.Content>Body</Dialog.Content>
<Dialog.Footer>Footer</Dialog.Footer>
</Dialog>
</Modal>
);

const panel = screen
.getByRole('dialog')
.querySelector('.tw\\:bg-overlay-surface');

expect(panel).not.toBeNull();
expect(panel).toHaveClass('tw:bg-overlay-surface', 'tw:shadow-overlay');
// The page background would leave the modal flush with the scrim behind it.
expect(panel).not.toHaveClass('tw:bg-primary');
});

it('divides the footer with the subtle border role', () => {
render(
<Modal isOpen>
<Dialog title="Settings">
<Dialog.Content>Body</Dialog.Content>
<Dialog.Footer>Footer</Dialog.Footer>
</Dialog>
</Modal>
);

const footer = screen
.getByRole('dialog')
.querySelector('.tw\\:border-t.tw\\:border-subtle');

expect(footer).not.toBeNull();
expect(footer).not.toHaveClass('tw:border-secondary');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ interface DialogFooterProps {
const DialogFooter = ({ children, className }: DialogFooterProps) => (
<div
className={cx(
'tw:z-10 tw:mt-6 tw:sm:mt-8 tw:border-t tw:border-secondary',
'tw:z-10 tw:mt-6 tw:sm:mt-8 tw:border-t tw:border-subtle',
className
)}>
<div className="tw:flex tw:flex-1 tw:gap-3 tw:sm:px-6 tw:px-4 tw:py-4 tw:justify-end">
Expand Down Expand Up @@ -153,7 +153,7 @@ const DialogBase = ({
{({ close }) => (
<div
className={cx(
'tw:relative tw:w-full tw:rounded-2xl tw:bg-primary tw:shadow-xl',
'tw:relative tw:w-full tw:rounded-2xl tw:bg-overlay-surface tw:shadow-overlay',
panelClassName
)}
style={{ maxWidth: width }}>
Expand All @@ -165,7 +165,7 @@ const DialogBase = ({
title={title}
/>
<div className="tw:h-5 tw:w-full" />
<div className="tw:w-full tw:border-t tw:border-secondary" />
<div className="tw:w-full tw:border-t tw:border-subtle" />
</>
)}
{children}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { Dialog, Modal } from './slideout-menu';

describe('SlideoutMenu theme roles', () => {
it('renders the drawer panel on the overlay surface with overlay elevation', () => {
render(
<Modal isOpen>
<Dialog aria-label="Filters">Body</Dialog>
</Modal>
);

const panel = screen.getByRole('dialog');

expect(panel).toHaveClass('tw:bg-overlay-surface');
expect(panel).not.toHaveClass('tw:bg-primary');
// Modal wrapper owns the elevation shadow.
expect(panel.closest('.tw\\:shadow-overlay')).not.toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const Modal = (props: ModalProps) => (
{...props}
className={(state) =>
cx(
'tw:inset-y-0 tw:right-0 tw:h-full tw:w-full tw:max-w-100 tw:shadow-xl tw:transition',
'tw:inset-y-0 tw:right-0 tw:h-full tw:w-full tw:max-w-100 tw:shadow-overlay tw:transition',
state.isEntering &&
'tw:duration-300 tw:animate-in tw:slide-in-from-right',
state.isExiting &&
Expand All @@ -72,7 +72,7 @@ export const Dialog = (props: DialogProps) => (
className={cx(
// `outline-hidden` removed: the outline now draws this panel's border (it replaced a
// ring, which WebKit does not pixel-snap), so suppressing it would erase the border.
'tw:relative tw:flex tw:size-full tw:flex-col tw:items-start tw:gap-6 tw:overflow-y-auto tw:bg-primary tw:outline-1 tw:outline-secondary_alt',
'tw:relative tw:flex tw:size-full tw:flex-col tw:items-start tw:gap-6 tw:overflow-y-auto tw:bg-overlay-surface tw:outline-1 tw:outline-secondary_alt',
props.className
)}
/>
Expand Down Expand Up @@ -170,7 +170,7 @@ const Footer = (props: ComponentPropsWithRef<'footer'>) => {
<footer
{...props}
className={cx(
'tw:w-full tw:p-4 tw:shadow-[inset_0px_1px_0px_0px] tw:shadow-border-secondary tw:md:px-6',
'tw:w-full tw:border-t tw:border-subtle tw:p-4 tw:md:px-6',
props.className
)}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { Button } from '@/components/base/buttons/button';
import { Dropdown } from './dropdown';

const renderDropdown = () =>
render(
<Dropdown.Root>
<Button>Open</Button>
<Dropdown.Popover>
<Dropdown.Menu>
<Dropdown.Item id="one">One</Dropdown.Item>
<Dropdown.Separator />
<Dropdown.Item id="two">Two</Dropdown.Item>
</Dropdown.Menu>
</Dropdown.Popover>
</Dropdown.Root>
);

describe('Dropdown theme roles', () => {
it('renders the menu on the raised surface with raised elevation', () => {
renderDropdown();

fireEvent.click(screen.getByRole('button', { name: 'Open' }));

const surface = screen.getByRole('menu').closest('.tw\\:bg-raised');

expect(surface).not.toBeNull();
expect(surface).toHaveClass('tw:bg-raised', 'tw:shadow-raised');
// Menus are raised above surfaces; the page background would erase that.
expect(surface).not.toHaveClass('tw:bg-primary');
});

it('draws separators with the subtle border role, not a solid gray fill', () => {
renderDropdown();

fireEvent.click(screen.getByRole('button', { name: 'Open' }));

const separator = screen
.getByRole('menu')
.querySelector('.tw\\:border-subtle');

expect(separator).not.toBeNull();
expect(separator).not.toHaveClass('tw:bg-border-secondary');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const DropdownPopover = (props: DropdownPopoverProps) => {
{...rest}
className={(state) =>
cx(
'tw:w-62 tw:max-h-none! tw:origin-(--trigger-anchor-point) tw:overflow-hidden tw:rounded-lg tw:bg-primary tw:shadow-lg tw:outline-1 tw:outline-secondary_alt tw:will-change-transform',
'tw:w-62 tw:max-h-none! tw:origin-(--trigger-anchor-point) tw:overflow-hidden tw:rounded-lg tw:bg-raised tw:shadow-raised tw:outline-1 tw:outline-secondary_alt tw:will-change-transform',
state.isEntering &&
'tw:duration-150 tw:ease-out tw:animate-in tw:fade-in tw:placement-right:slide-in-from-left-0.5 tw:placement-top:slide-in-from-bottom-0.5 tw:placement-bottom:slide-in-from-top-0.5',
state.isExiting &&
Expand All @@ -168,7 +168,7 @@ const DropdownSeparator = (props: AriaSeparatorProps) => {
<AriaSeparator
{...props}
className={cx(
'tw:my-1 tw:h-px tw:w-full tw:bg-border-secondary',
'tw:my-1 tw:w-full tw:border-t tw:border-subtle',
props.className
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const Popover = (props: PopoverProps) => {
// thin/vanish in Safari when zoomed out). This ring had no `ring-inset`, so it
// drew outward from the border-box edge — outline-offset 0 (the default) matches
// that exactly. `outline-hidden` is gone: it would suppress this border.
'tw:max-h-64! tw:w-(--trigger-width) tw:origin-(--trigger-anchor-point) tw:overflow-x-hidden tw:overflow-y-auto tw:rounded-lg tw:bg-primary tw:py-1 tw:shadow-lg tw:outline-1 tw:outline-secondary_alt tw:will-change-transform',
'tw:max-h-64! tw:w-(--trigger-width) tw:origin-(--trigger-anchor-point) tw:overflow-x-hidden tw:overflow-y-auto tw:rounded-lg tw:bg-raised tw:py-1 tw:shadow-raised tw:outline-1 tw:outline-secondary_alt tw:will-change-transform',

state.isEntering &&
'tw:duration-150 tw:ease-out tw:animate-in tw:fade-in tw:placement-right:slide-in-from-left-0.5 tw:placement-top:slide-in-from-bottom-0.5 tw:placement-bottom:slide-in-from-top-0.5',
Expand Down
Loading