@slipstream-ui/core 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +184 -8
- package/dist/index.d.ts +184 -8
- package/dist/index.js +1609 -887
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1651 -933
- package/dist/index.mjs.map +1 -1
- package/dist/manifests/accordion.manifest.json +2 -2
- package/dist/manifests/alert.manifest.json +1 -1
- package/dist/manifests/announcement-bar.manifest.json +1 -1
- package/dist/manifests/app-shell.manifest.json +1 -1
- package/dist/manifests/applied-filters.manifest.json +1 -1
- package/dist/manifests/article-card.manifest.json +1 -1
- package/dist/manifests/auth-layout.manifest.json +1 -1
- package/dist/manifests/autocomplete.manifest.json +1 -1
- package/dist/manifests/avatar.manifest.json +1 -1
- package/dist/manifests/badge.manifest.json +1 -1
- package/dist/manifests/block.manifest.json +1 -1
- package/dist/manifests/bottom-nav.manifest.json +1 -1
- package/dist/manifests/breadcrumb.manifest.json +1 -1
- package/dist/manifests/button-group.manifest.json +1 -1
- package/dist/manifests/button.manifest.json +1 -1
- package/dist/manifests/calendar.manifest.json +175 -0
- package/dist/manifests/card.manifest.json +1 -1
- package/dist/manifests/checkbox.manifest.json +1 -1
- package/dist/manifests/comparison-table.manifest.json +1 -1
- package/dist/manifests/confirm-dialog.manifest.json +1 -1
- package/dist/manifests/contact-strip.manifest.json +1 -1
- package/dist/manifests/container.manifest.json +1 -1
- package/dist/manifests/cta-section.manifest.json +1 -1
- package/dist/manifests/data-table.manifest.json +8 -1
- package/dist/manifests/date-picker-popover.manifest.json +202 -0
- package/dist/manifests/date-picker.manifest.json +1 -1
- package/dist/manifests/date-range-picker.manifest.json +1 -1
- package/dist/manifests/deal-card.manifest.json +1 -1
- package/dist/manifests/dialog.manifest.json +1 -1
- package/dist/manifests/document-card.manifest.json +1 -1
- package/dist/manifests/drawer.manifest.json +1 -1
- package/dist/manifests/empty-state.manifest.json +1 -1
- package/dist/manifests/entity-card.manifest.json +1 -1
- package/dist/manifests/feature-grid.manifest.json +1 -1
- package/dist/manifests/feature-row.manifest.json +1 -1
- package/dist/manifests/fieldset.manifest.json +1 -1
- package/dist/manifests/file-upload.manifest.json +1 -1
- package/dist/manifests/filter-bar.manifest.json +1 -1
- package/dist/manifests/filter-chips.manifest.json +1 -1
- package/dist/manifests/filter-panel.manifest.json +1 -1
- package/dist/manifests/flex.manifest.json +1 -1
- package/dist/manifests/form-field.manifest.json +1 -1
- package/dist/manifests/form-layout.manifest.json +1 -1
- package/dist/manifests/form.manifest.json +1 -1
- package/dist/manifests/grid.manifest.json +1 -1
- package/dist/manifests/heading.manifest.json +1 -1
- package/dist/manifests/hero.manifest.json +1 -1
- package/dist/manifests/image.manifest.json +142 -0
- package/dist/manifests/input-group.manifest.json +1 -1
- package/dist/manifests/input.manifest.json +1 -1
- package/dist/manifests/label.manifest.json +1 -1
- package/dist/manifests/link-tabs.manifest.json +1 -1
- package/dist/manifests/link.manifest.json +1 -1
- package/dist/manifests/list.manifest.json +1 -1
- package/dist/manifests/load-more.manifest.json +1 -1
- package/dist/manifests/logo-cloud.manifest.json +1 -1
- package/dist/manifests/menu.manifest.json +1 -1
- package/dist/manifests/metric-card.manifest.json +1 -1
- package/dist/manifests/multi-select.manifest.json +1 -1
- package/dist/manifests/newsletter.manifest.json +1 -1
- package/dist/manifests/page-header.manifest.json +1 -1
- package/dist/manifests/pagination.manifest.json +1 -1
- package/dist/manifests/password-input.manifest.json +1 -1
- package/dist/manifests/popover.manifest.json +86 -4
- package/dist/manifests/process-steps.manifest.json +1 -1
- package/dist/manifests/progress.manifest.json +1 -1
- package/dist/manifests/prose.manifest.json +1 -1
- package/dist/manifests/radio.manifest.json +1 -1
- package/dist/manifests/range-slider.manifest.json +1 -1
- package/dist/manifests/search.manifest.json +1 -1
- package/dist/manifests/section-heading.manifest.json +1 -1
- package/dist/manifests/section.manifest.json +1 -1
- package/dist/manifests/segmented-control.manifest.json +1 -1
- package/dist/manifests/select-menu.manifest.json +1 -1
- package/dist/manifests/select.manifest.json +1 -1
- package/dist/manifests/separator.manifest.json +1 -1
- package/dist/manifests/site-footer.manifest.json +1 -1
- package/dist/manifests/site-header.manifest.json +13 -3
- package/dist/manifests/skeleton.manifest.json +1 -1
- package/dist/manifests/spinner.manifest.json +1 -1
- package/dist/manifests/stat-band.manifest.json +1 -1
- package/dist/manifests/stepper.manifest.json +7 -1
- package/dist/manifests/switch.manifest.json +1 -1
- package/dist/manifests/table-card.manifest.json +1 -1
- package/dist/manifests/table-of-contents.manifest.json +1 -1
- package/dist/manifests/table.manifest.json +1 -1
- package/dist/manifests/tabs.manifest.json +1 -1
- package/dist/manifests/testimonial.manifest.json +1 -1
- package/dist/manifests/text.manifest.json +1 -1
- package/dist/manifests/textarea.manifest.json +1 -1
- package/dist/manifests/theme-toggle.manifest.json +1 -1
- package/dist/manifests/time-picker.manifest.json +1 -1
- package/dist/manifests/timeline.manifest.json +1 -1
- package/dist/manifests/toast.manifest.json +1 -1
- package/dist/manifests/tombstone-card.manifest.json +1 -1
- package/dist/manifests/tooltip.manifest.json +1 -1
- package/dist/src/components/alert/Alert.js +1 -1
- package/dist/src/components/alert/Alert.js.map +1 -1
- package/dist/src/components/alert/Alert.mjs +1 -1
- package/dist/src/components/alert/Alert.mjs.map +1 -1
- package/dist/src/components/app-shell/AppShell.js +1 -1
- package/dist/src/components/app-shell/AppShell.js.map +1 -1
- package/dist/src/components/app-shell/AppShell.mjs +1 -1
- package/dist/src/components/app-shell/AppShell.mjs.map +1 -1
- package/dist/src/components/article-card/ArticleCard.js +2 -2
- package/dist/src/components/article-card/ArticleCard.js.map +1 -1
- package/dist/src/components/article-card/ArticleCard.mjs +2 -2
- package/dist/src/components/article-card/ArticleCard.mjs.map +1 -1
- package/dist/src/components/calendar/Calendar.d.ts +34 -0
- package/dist/src/components/calendar/Calendar.js +233 -0
- package/dist/src/components/calendar/Calendar.js.map +1 -0
- package/dist/src/components/calendar/Calendar.mjs +208 -0
- package/dist/src/components/calendar/Calendar.mjs.map +1 -0
- package/dist/src/components/calendar/index.d.ts +1 -0
- package/dist/src/components/calendar/index.js +23 -0
- package/dist/src/components/calendar/index.js.map +1 -0
- package/dist/src/components/calendar/index.mjs +2 -0
- package/dist/src/components/calendar/index.mjs.map +1 -0
- package/dist/src/components/comparison-table/ComparisonTable.js +1 -1
- package/dist/src/components/comparison-table/ComparisonTable.js.map +1 -1
- package/dist/src/components/comparison-table/ComparisonTable.mjs +1 -1
- package/dist/src/components/comparison-table/ComparisonTable.mjs.map +1 -1
- package/dist/src/components/cta-section/CTASection.js +1 -1
- package/dist/src/components/cta-section/CTASection.js.map +1 -1
- package/dist/src/components/cta-section/CTASection.mjs +1 -1
- package/dist/src/components/cta-section/CTASection.mjs.map +1 -1
- package/dist/src/components/data-table/DataTable.d.ts +3 -1
- package/dist/src/components/data-table/DataTable.js +2 -4
- package/dist/src/components/data-table/DataTable.js.map +1 -1
- package/dist/src/components/data-table/DataTable.mjs +2 -4
- package/dist/src/components/data-table/DataTable.mjs.map +1 -1
- package/dist/src/components/date-picker-popover/DatePickerPopover.d.ts +33 -0
- package/dist/src/components/date-picker-popover/DatePickerPopover.js +117 -0
- package/dist/src/components/date-picker-popover/DatePickerPopover.js.map +1 -0
- package/dist/src/components/date-picker-popover/DatePickerPopover.mjs +83 -0
- package/dist/src/components/date-picker-popover/DatePickerPopover.mjs.map +1 -0
- package/dist/src/components/date-picker-popover/index.d.ts +1 -0
- package/dist/src/components/date-picker-popover/index.js +23 -0
- package/dist/src/components/date-picker-popover/index.js.map +1 -0
- package/dist/src/components/date-picker-popover/index.mjs +2 -0
- package/dist/src/components/date-picker-popover/index.mjs.map +1 -0
- package/dist/src/components/image/Image.d.ts +34 -0
- package/dist/src/components/image/Image.js +75 -0
- package/dist/src/components/image/Image.js.map +1 -0
- package/dist/src/components/image/Image.mjs +41 -0
- package/dist/src/components/image/Image.mjs.map +1 -0
- package/dist/src/components/image/index.d.ts +1 -0
- package/dist/src/components/image/index.js +29 -0
- package/dist/src/components/image/index.js.map +1 -0
- package/dist/src/components/image/index.mjs +5 -0
- package/dist/src/components/image/index.mjs.map +1 -0
- package/dist/src/components/link/Link.js +4 -4
- package/dist/src/components/link/Link.js.map +1 -1
- package/dist/src/components/link/Link.mjs +4 -4
- package/dist/src/components/link/Link.mjs.map +1 -1
- package/dist/src/components/page-header/PageHeader.js +1 -1
- package/dist/src/components/page-header/PageHeader.js.map +1 -1
- package/dist/src/components/page-header/PageHeader.mjs +1 -1
- package/dist/src/components/page-header/PageHeader.mjs.map +1 -1
- package/dist/src/components/popover/Popover.d.ts +36 -3
- package/dist/src/components/popover/Popover.js +118 -22
- package/dist/src/components/popover/Popover.js.map +1 -1
- package/dist/src/components/popover/Popover.mjs +117 -22
- package/dist/src/components/popover/Popover.mjs.map +1 -1
- package/dist/src/components/section-heading/SectionHeading.js +1 -1
- package/dist/src/components/section-heading/SectionHeading.js.map +1 -1
- package/dist/src/components/section-heading/SectionHeading.mjs +1 -1
- package/dist/src/components/section-heading/SectionHeading.mjs.map +1 -1
- package/dist/src/components/site-header/SiteHeader.d.ts +25 -3
- package/dist/src/components/site-header/SiteHeader.js +141 -6
- package/dist/src/components/site-header/SiteHeader.js.map +1 -1
- package/dist/src/components/site-header/SiteHeader.mjs +141 -6
- package/dist/src/components/site-header/SiteHeader.mjs.map +1 -1
- package/dist/src/components/stepper/Stepper.d.ts +18 -0
- package/dist/src/components/stepper/Stepper.js +2 -1
- package/dist/src/components/stepper/Stepper.js.map +1 -1
- package/dist/src/components/stepper/Stepper.mjs +2 -1
- package/dist/src/components/stepper/Stepper.mjs.map +1 -1
- package/dist/src/index.d.ts +3 -0
- package/dist/src/utils/date.d.ts +32 -0
- package/dist/src/utils/date.js +171 -0
- package/dist/src/utils/date.js.map +1 -0
- package/dist/src/utils/date.mjs +134 -0
- package/dist/src/utils/date.mjs.map +1 -0
- package/dist/src/utils/position.d.ts +42 -0
- package/dist/src/utils/position.js +91 -0
- package/dist/src/utils/position.js.map +1 -0
- package/dist/src/utils/position.mjs +67 -0
- package/dist/src/utils/position.mjs.map +1 -0
- package/dist/styles-full.css +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/components/alert/Alert.tsx +1 -1
- package/src/components/app-shell/AppShell.tsx +1 -1
- package/src/components/article-card/ArticleCard.tsx +2 -2
- package/src/components/calendar/Calendar.test.tsx +277 -0
- package/src/components/calendar/Calendar.tsx +273 -0
- package/src/components/calendar/index.ts +1 -0
- package/src/components/comparison-table/ComparisonTable.tsx +1 -1
- package/src/components/cta-section/CTASection.tsx +1 -1
- package/src/components/data-table/DataTable.test.tsx +21 -0
- package/src/components/data-table/DataTable.tsx +4 -1
- package/src/components/date-picker-popover/DatePickerPopover.test.tsx +223 -0
- package/src/components/date-picker-popover/DatePickerPopover.tsx +117 -0
- package/src/components/date-picker-popover/index.ts +1 -0
- package/src/components/image/Image.test.tsx +94 -0
- package/src/components/image/Image.tsx +71 -0
- package/src/components/image/index.ts +1 -0
- package/src/components/link/Link.test.tsx +2 -1
- package/src/components/link/Link.tsx +4 -4
- package/src/components/page-header/PageHeader.tsx +1 -1
- package/src/components/popover/Popover.test.tsx +307 -3
- package/src/components/popover/Popover.tsx +228 -91
- package/src/components/section-heading/SectionHeading.tsx +1 -1
- package/src/components/site-header/SiteHeader.test.tsx +103 -1
- package/src/components/site-header/SiteHeader.tsx +220 -16
- package/src/components/stepper/Stepper.test.tsx +12 -0
- package/src/components/stepper/Stepper.tsx +15 -1
- package/src/index.ts +3 -0
- package/src/manifests/accordion.manifest.json +2 -2
- package/src/manifests/alert.manifest.json +1 -1
- package/src/manifests/announcement-bar.manifest.json +1 -1
- package/src/manifests/app-shell.manifest.json +1 -1
- package/src/manifests/applied-filters.manifest.json +1 -1
- package/src/manifests/article-card.manifest.json +1 -1
- package/src/manifests/auth-layout.manifest.json +1 -1
- package/src/manifests/autocomplete.manifest.json +1 -1
- package/src/manifests/avatar.manifest.json +1 -1
- package/src/manifests/badge.manifest.json +1 -1
- package/src/manifests/block.manifest.json +1 -1
- package/src/manifests/bottom-nav.manifest.json +1 -1
- package/src/manifests/breadcrumb.manifest.json +1 -1
- package/src/manifests/button-group.manifest.json +1 -1
- package/src/manifests/button.manifest.json +1 -1
- package/src/manifests/calendar.manifest.json +175 -0
- package/src/manifests/card.manifest.json +1 -1
- package/src/manifests/checkbox.manifest.json +1 -1
- package/src/manifests/comparison-table.manifest.json +1 -1
- package/src/manifests/confirm-dialog.manifest.json +1 -1
- package/src/manifests/contact-strip.manifest.json +1 -1
- package/src/manifests/container.manifest.json +1 -1
- package/src/manifests/cta-section.manifest.json +1 -1
- package/src/manifests/data-table.manifest.json +8 -1
- package/src/manifests/date-picker-popover.manifest.json +202 -0
- package/src/manifests/date-picker.manifest.json +1 -1
- package/src/manifests/date-range-picker.manifest.json +1 -1
- package/src/manifests/deal-card.manifest.json +1 -1
- package/src/manifests/dialog.manifest.json +1 -1
- package/src/manifests/document-card.manifest.json +1 -1
- package/src/manifests/drawer.manifest.json +1 -1
- package/src/manifests/empty-state.manifest.json +1 -1
- package/src/manifests/entity-card.manifest.json +1 -1
- package/src/manifests/feature-grid.manifest.json +1 -1
- package/src/manifests/feature-row.manifest.json +1 -1
- package/src/manifests/fieldset.manifest.json +1 -1
- package/src/manifests/file-upload.manifest.json +1 -1
- package/src/manifests/filter-bar.manifest.json +1 -1
- package/src/manifests/filter-chips.manifest.json +1 -1
- package/src/manifests/filter-panel.manifest.json +1 -1
- package/src/manifests/flex.manifest.json +1 -1
- package/src/manifests/form-field.manifest.json +1 -1
- package/src/manifests/form-layout.manifest.json +1 -1
- package/src/manifests/form.manifest.json +1 -1
- package/src/manifests/grid.manifest.json +1 -1
- package/src/manifests/heading.manifest.json +1 -1
- package/src/manifests/hero.manifest.json +1 -1
- package/src/manifests/image.manifest.json +142 -0
- package/src/manifests/input-group.manifest.json +1 -1
- package/src/manifests/input.manifest.json +1 -1
- package/src/manifests/label.manifest.json +1 -1
- package/src/manifests/link-tabs.manifest.json +1 -1
- package/src/manifests/link.manifest.json +1 -1
- package/src/manifests/list.manifest.json +1 -1
- package/src/manifests/load-more.manifest.json +1 -1
- package/src/manifests/logo-cloud.manifest.json +1 -1
- package/src/manifests/menu.manifest.json +1 -1
- package/src/manifests/metric-card.manifest.json +1 -1
- package/src/manifests/multi-select.manifest.json +1 -1
- package/src/manifests/newsletter.manifest.json +1 -1
- package/src/manifests/page-header.manifest.json +1 -1
- package/src/manifests/pagination.manifest.json +1 -1
- package/src/manifests/password-input.manifest.json +1 -1
- package/src/manifests/popover.manifest.json +86 -4
- package/src/manifests/process-steps.manifest.json +1 -1
- package/src/manifests/progress.manifest.json +1 -1
- package/src/manifests/prose.manifest.json +1 -1
- package/src/manifests/radio.manifest.json +1 -1
- package/src/manifests/range-slider.manifest.json +1 -1
- package/src/manifests/search.manifest.json +1 -1
- package/src/manifests/section-heading.manifest.json +1 -1
- package/src/manifests/section.manifest.json +1 -1
- package/src/manifests/segmented-control.manifest.json +1 -1
- package/src/manifests/select-menu.manifest.json +1 -1
- package/src/manifests/select.manifest.json +1 -1
- package/src/manifests/separator.manifest.json +1 -1
- package/src/manifests/site-footer.manifest.json +1 -1
- package/src/manifests/site-header.manifest.json +13 -3
- package/src/manifests/skeleton.manifest.json +1 -1
- package/src/manifests/spinner.manifest.json +1 -1
- package/src/manifests/stat-band.manifest.json +1 -1
- package/src/manifests/stepper.manifest.json +7 -1
- package/src/manifests/switch.manifest.json +1 -1
- package/src/manifests/table-card.manifest.json +1 -1
- package/src/manifests/table-of-contents.manifest.json +1 -1
- package/src/manifests/table.manifest.json +1 -1
- package/src/manifests/tabs.manifest.json +1 -1
- package/src/manifests/testimonial.manifest.json +1 -1
- package/src/manifests/text.manifest.json +1 -1
- package/src/manifests/textarea.manifest.json +1 -1
- package/src/manifests/theme-toggle.manifest.json +1 -1
- package/src/manifests/time-picker.manifest.json +1 -1
- package/src/manifests/timeline.manifest.json +1 -1
- package/src/manifests/toast.manifest.json +1 -1
- package/src/manifests/tombstone-card.manifest.json +1 -1
- package/src/manifests/tooltip.manifest.json +1 -1
- package/src/utils/date.test.ts +190 -0
- package/src/utils/date.ts +162 -0
- package/src/utils/position.test.ts +227 -0
- package/src/utils/position.ts +129 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
+
import { renderToString } from 'react-dom/server';
|
|
3
|
+
import { axe } from 'jest-axe';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { Image } from './Image';
|
|
6
|
+
|
|
7
|
+
describe('Image', () => {
|
|
8
|
+
it('renders the primary source with intrinsic dimensions and lazy loading', () => {
|
|
9
|
+
render(<Image src="/event.jpg" alt="Fall Classic" />);
|
|
10
|
+
const img = screen.getByRole('img', { name: 'Fall Classic' });
|
|
11
|
+
expect(img).toHaveAttribute('src', '/event.jpg');
|
|
12
|
+
expect(img).toHaveAttribute('width', '1200');
|
|
13
|
+
expect(img).toHaveAttribute('height', '630');
|
|
14
|
+
expect(img).toHaveAttribute('loading', 'lazy');
|
|
15
|
+
expect(img).toHaveAttribute('fetchpriority', 'auto');
|
|
16
|
+
expect(img).toHaveAttribute('decoding', 'async');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('loads eagerly only when priority is set', () => {
|
|
20
|
+
render(<Image src="/hero.jpg" alt="Hero" priority width={1600} height={900} />);
|
|
21
|
+
const img = screen.getByRole('img', { name: 'Hero' });
|
|
22
|
+
expect(img).toHaveAttribute('loading', 'eager');
|
|
23
|
+
expect(img).toHaveAttribute('fetchpriority', 'high');
|
|
24
|
+
expect(img).toHaveAttribute('width', '1600');
|
|
25
|
+
expect(img).toHaveAttribute('height', '900');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('falls back to fallbackSrc after the primary fails', () => {
|
|
29
|
+
render(
|
|
30
|
+
<Image src="/broken.jpg" fallbackSrc="/placeholder.svg" alt="Event" />
|
|
31
|
+
);
|
|
32
|
+
const img = screen.getByRole('img', { name: 'Event' });
|
|
33
|
+
fireEvent.error(img);
|
|
34
|
+
expect(screen.getByRole('img', { name: 'Event' })).toHaveAttribute(
|
|
35
|
+
'src',
|
|
36
|
+
'/placeholder.svg'
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('renders the fallback node when both URLs fail', () => {
|
|
41
|
+
render(
|
|
42
|
+
<Image
|
|
43
|
+
src="/broken.jpg"
|
|
44
|
+
fallbackSrc="/also-broken.svg"
|
|
45
|
+
alt="Event"
|
|
46
|
+
fallback={<span data-testid="fallback">No image</span>}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
fireEvent.error(screen.getByRole('img', { name: 'Event' }));
|
|
50
|
+
fireEvent.error(screen.getByRole('img', { name: 'Event' }));
|
|
51
|
+
expect(screen.queryByRole('img')).not.toBeInTheDocument();
|
|
52
|
+
expect(screen.getByTestId('fallback')).toHaveTextContent('No image');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('renders the fallback node on the first error without a fallbackSrc', () => {
|
|
56
|
+
render(
|
|
57
|
+
<Image src="/broken.jpg" alt="Event" fallback={<span data-testid="fallback">No image</span>} />
|
|
58
|
+
);
|
|
59
|
+
fireEvent.error(screen.getByRole('img', { name: 'Event' }));
|
|
60
|
+
expect(screen.getByTestId('fallback')).toBeInTheDocument();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('renders nothing when it fails without a fallback node', () => {
|
|
64
|
+
const { container } = render(<Image src="/broken.jpg" alt="Event" />);
|
|
65
|
+
fireEvent.error(screen.getByRole('img', { name: 'Event' }));
|
|
66
|
+
expect(container).toBeEmptyDOMElement();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('keeps dimensions in server-rendered markup', () => {
|
|
70
|
+
const html = renderToString(<Image src="/event.jpg" alt="Event" width={640} height={360} />);
|
|
71
|
+
expect(html).toContain('width="640"');
|
|
72
|
+
expect(html).toContain('height="360"');
|
|
73
|
+
expect(html).toContain('alt="Event"');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('merges className and imgClassName', () => {
|
|
77
|
+
render(
|
|
78
|
+
<Image
|
|
79
|
+
src="/event.jpg"
|
|
80
|
+
alt="Event"
|
|
81
|
+
className="rounded-md"
|
|
82
|
+
imgClassName="object-cover"
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
const img = screen.getByRole('img', { name: 'Event' });
|
|
86
|
+
expect(img).toHaveClass('rounded-md');
|
|
87
|
+
expect(img).toHaveClass('object-cover');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('has no accessibility violations', async () => {
|
|
91
|
+
const { container } = render(<Image src="/event.jpg" alt="Fall Classic" />);
|
|
92
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { cn } from '../../utils/cn';
|
|
5
|
+
|
|
6
|
+
export type ImageProps = {
|
|
7
|
+
/** Primary image URL. Hotlinked sources are expected. */
|
|
8
|
+
src: string;
|
|
9
|
+
/** Required: describes the image, not the component. */
|
|
10
|
+
alt: string;
|
|
11
|
+
/** Second chance before the fallback node (e.g. generated placeholder art). */
|
|
12
|
+
fallbackSrc?: string;
|
|
13
|
+
/** Rendered when every URL has failed (icon, initials, empty panel). */
|
|
14
|
+
fallback?: React.ReactNode;
|
|
15
|
+
/** Load eagerly and fetch at high priority for the LCP image. */
|
|
16
|
+
priority?: boolean;
|
|
17
|
+
/** Intrinsic width; always emitted so the browser reserves space. */
|
|
18
|
+
width?: number;
|
|
19
|
+
/** Intrinsic height; always emitted so the browser reserves space. */
|
|
20
|
+
height?: number;
|
|
21
|
+
/** Classes for the image; merged with imgClassName. */
|
|
22
|
+
className?: string;
|
|
23
|
+
/** Classes for the image when a consumer wants to keep them separate. */
|
|
24
|
+
imgClassName?: string;
|
|
25
|
+
style?: React.CSSProperties;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Resilient image: `src` -> `fallbackSrc` -> `fallback` node.
|
|
30
|
+
*
|
|
31
|
+
* Organizer images are hotlinked and occasionally 403, move, or die. Cards
|
|
32
|
+
* must never show a broken-image box or shift layout when that happens, so
|
|
33
|
+
* intrinsic dimensions are always rendered and only the priority image is
|
|
34
|
+
* eager.
|
|
35
|
+
*/
|
|
36
|
+
export function Image({
|
|
37
|
+
src,
|
|
38
|
+
alt,
|
|
39
|
+
fallbackSrc,
|
|
40
|
+
fallback,
|
|
41
|
+
priority = false,
|
|
42
|
+
width = 1200,
|
|
43
|
+
height = 630,
|
|
44
|
+
className,
|
|
45
|
+
imgClassName,
|
|
46
|
+
style,
|
|
47
|
+
}: ImageProps) {
|
|
48
|
+
const [stage, setStage] = React.useState<0 | 1 | 2>(0);
|
|
49
|
+
|
|
50
|
+
const onError = () => setStage((current) => (current === 0 && fallbackSrc ? 1 : 2));
|
|
51
|
+
const current = stage === 0 ? src : stage === 1 ? fallbackSrc : null;
|
|
52
|
+
|
|
53
|
+
if (!current || stage === 2) return <>{fallback ?? null}</>;
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<img
|
|
57
|
+
src={current}
|
|
58
|
+
alt={alt}
|
|
59
|
+
width={width}
|
|
60
|
+
height={height}
|
|
61
|
+
loading={priority ? 'eager' : 'lazy'}
|
|
62
|
+
fetchPriority={priority ? 'high' : 'auto'}
|
|
63
|
+
decoding="async"
|
|
64
|
+
className={cn(className, imgClassName)}
|
|
65
|
+
style={style}
|
|
66
|
+
onError={onError}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
Image.displayName = 'Image';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Image, type ImageProps } from './Image';
|
|
@@ -8,7 +8,8 @@ describe('Link', () => {
|
|
|
8
8
|
render(<Link href="/docs">Docs</Link>);
|
|
9
9
|
const link = screen.getByRole('link', { name: 'Docs' });
|
|
10
10
|
expect(link).toHaveAttribute('href', '/docs');
|
|
11
|
-
expect(link).toHaveClass('text-primary');
|
|
11
|
+
expect(link).toHaveClass('text-primary-ink');
|
|
12
|
+
expect(link).not.toHaveClass('text-primary');
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
it('auto-detects external URLs and adds rel/noopener', () => {
|
|
@@ -8,11 +8,11 @@ import { cn } from '../../utils/cn';
|
|
|
8
8
|
const linkVariants = cva('inline-flex items-center gap-1 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background rounded-sm', {
|
|
9
9
|
variants: {
|
|
10
10
|
variant: {
|
|
11
|
-
default: 'text-primary hover:underline underline-offset-4',
|
|
11
|
+
default: 'text-primary-ink hover:underline underline-offset-4',
|
|
12
12
|
muted: 'text-muted-foreground hover:text-foreground',
|
|
13
|
-
underline: 'underline underline-offset-4 hover:text-primary',
|
|
14
|
-
arrow: 'font-medium text-primary hover:underline underline-offset-4',
|
|
15
|
-
external: 'text-primary hover:underline underline-offset-4',
|
|
13
|
+
underline: 'underline underline-offset-4 hover:text-primary-ink',
|
|
14
|
+
arrow: 'font-medium text-primary-ink hover:underline underline-offset-4',
|
|
15
|
+
external: 'text-primary-ink hover:underline underline-offset-4',
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
defaultVariants: { variant: 'default' },
|
|
@@ -47,7 +47,7 @@ export const PageHeader = React.forwardRef<HTMLDivElement, PageHeaderProps>(func
|
|
|
47
47
|
<div ref={ref} className={cn('flex flex-col gap-2', align === 'center' && 'items-center text-center', className)} {...props}>
|
|
48
48
|
{breadcrumbs && <div className="text-sm text-muted-foreground">{breadcrumbs}</div>}
|
|
49
49
|
{eyebrow && (
|
|
50
|
-
<div className={cn('text-xs font-medium uppercase tracking-wide text-primary', eyebrowClassName)}>{eyebrow}</div>
|
|
50
|
+
<div className={cn('text-xs font-medium uppercase tracking-wide text-primary-ink', eyebrowClassName)}>{eyebrow}</div>
|
|
51
51
|
)}
|
|
52
52
|
<div className={cn('flex w-full flex-wrap items-start justify-between gap-3', align === 'center' && 'justify-center')}>
|
|
53
53
|
<div className={cn('min-w-0', align === 'center' && 'flex flex-col items-center')}>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
|
1
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
2
2
|
import userEvent from '@testing-library/user-event';
|
|
3
3
|
import { axe } from 'jest-axe';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from './Popover';
|
|
6
7
|
|
|
7
8
|
function BasicPopover({ onOpenChange }: { onOpenChange?: (open: boolean) => void }) {
|
|
8
9
|
return (
|
|
@@ -16,6 +17,34 @@ function BasicPopover({ onOpenChange }: { onOpenChange?: (open: boolean) => void
|
|
|
16
17
|
);
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
function mockBounds(anchor: Partial<DOMRect>, panel: Partial<DOMRect> = {}) {
|
|
21
|
+
const toRect = (value: Partial<DOMRect>, fallback: DOMRect) => ({ ...fallback, ...value }) as DOMRect;
|
|
22
|
+
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
|
|
23
|
+
this: HTMLElement
|
|
24
|
+
) {
|
|
25
|
+
const empty = {
|
|
26
|
+
top: 0,
|
|
27
|
+
left: 0,
|
|
28
|
+
right: 0,
|
|
29
|
+
bottom: 0,
|
|
30
|
+
width: 0,
|
|
31
|
+
height: 0,
|
|
32
|
+
x: 0,
|
|
33
|
+
y: 0,
|
|
34
|
+
toJSON: () => ({}),
|
|
35
|
+
} as DOMRect;
|
|
36
|
+
if (this.getAttribute('role') === 'dialog') return toRect(panel, empty);
|
|
37
|
+
if (this.dataset.testid === 'anchor' || this.classList.contains('relative')) {
|
|
38
|
+
return toRect(anchor, empty);
|
|
39
|
+
}
|
|
40
|
+
return empty;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
vi.restoreAllMocks();
|
|
46
|
+
});
|
|
47
|
+
|
|
19
48
|
describe('Popover', () => {
|
|
20
49
|
it('renders trigger with dialog semantics', () => {
|
|
21
50
|
render(<BasicPopover />);
|
|
@@ -74,3 +103,278 @@ describe('Popover', () => {
|
|
|
74
103
|
expect(await axe(container)).toHaveNoViolations();
|
|
75
104
|
});
|
|
76
105
|
});
|
|
106
|
+
|
|
107
|
+
describe('Popover placement', () => {
|
|
108
|
+
it('opens below the anchor by default', async () => {
|
|
109
|
+
mockBounds({ top: 100, left: 40, width: 160, height: 32 }, { width: 288, height: 180 });
|
|
110
|
+
render(<BasicPopover />);
|
|
111
|
+
fireEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
112
|
+
const dialog = screen.getByRole('dialog');
|
|
113
|
+
expect(dialog).toHaveAttribute('data-side', 'bottom');
|
|
114
|
+
expect(dialog.style.top).toBe('140px');
|
|
115
|
+
expect(dialog.style.left).toBe('40px');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('opens above when the preferred side has no room', async () => {
|
|
119
|
+
mockBounds({ top: 700, left: 40, width: 160, height: 32 }, { width: 288, height: 180 });
|
|
120
|
+
render(
|
|
121
|
+
<Popover>
|
|
122
|
+
<PopoverTrigger>Open</PopoverTrigger>
|
|
123
|
+
<PopoverContent side="bottom">Panel</PopoverContent>
|
|
124
|
+
</Popover>
|
|
125
|
+
);
|
|
126
|
+
fireEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
127
|
+
const dialog = screen.getByRole('dialog');
|
|
128
|
+
expect(dialog).toHaveAttribute('data-side', 'top');
|
|
129
|
+
expect(dialog.style.top).toBe('512px');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('honours the side prop', async () => {
|
|
133
|
+
mockBounds({ top: 200, left: 300, width: 120, height: 36 }, { width: 200, height: 120 });
|
|
134
|
+
render(
|
|
135
|
+
<Popover>
|
|
136
|
+
<PopoverTrigger>Open</PopoverTrigger>
|
|
137
|
+
<PopoverContent side="right">Panel</PopoverContent>
|
|
138
|
+
</Popover>
|
|
139
|
+
);
|
|
140
|
+
fireEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
141
|
+
expect(screen.getByRole('dialog')).toHaveAttribute('data-side', 'right');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('matches the anchor width on request', async () => {
|
|
145
|
+
mockBounds({ top: 100, left: 40, width: 260, height: 32 }, { width: 288, height: 180 });
|
|
146
|
+
render(
|
|
147
|
+
<Popover>
|
|
148
|
+
<PopoverTrigger>Open</PopoverTrigger>
|
|
149
|
+
<PopoverContent matchTriggerWidth>Panel</PopoverContent>
|
|
150
|
+
</Popover>
|
|
151
|
+
);
|
|
152
|
+
fireEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
153
|
+
expect(screen.getByRole('dialog').style.width).toBe('260px');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('anchors to PopoverAnchor when present', async () => {
|
|
157
|
+
mockBounds({ top: 100, left: 0, width: 0, height: 0 }, { width: 200, height: 100 });
|
|
158
|
+
render(
|
|
159
|
+
<Popover>
|
|
160
|
+
<PopoverAnchor data-testid="anchor">Field</PopoverAnchor>
|
|
161
|
+
<PopoverTrigger>Open</PopoverTrigger>
|
|
162
|
+
<PopoverContent>Panel</PopoverContent>
|
|
163
|
+
</Popover>
|
|
164
|
+
);
|
|
165
|
+
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
|
|
166
|
+
this: HTMLElement
|
|
167
|
+
) {
|
|
168
|
+
const base = {
|
|
169
|
+
top: 0,
|
|
170
|
+
left: 0,
|
|
171
|
+
right: 0,
|
|
172
|
+
bottom: 0,
|
|
173
|
+
width: 0,
|
|
174
|
+
height: 0,
|
|
175
|
+
x: 0,
|
|
176
|
+
y: 0,
|
|
177
|
+
toJSON: () => ({}),
|
|
178
|
+
} as DOMRect;
|
|
179
|
+
if (this.getAttribute('role') === 'dialog') return { ...base, width: 200, height: 100 };
|
|
180
|
+
if (this.dataset.testid === 'anchor') {
|
|
181
|
+
return { ...base, top: 300, left: 24, width: 180, height: 40 };
|
|
182
|
+
}
|
|
183
|
+
return base;
|
|
184
|
+
});
|
|
185
|
+
fireEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
186
|
+
expect(screen.getByRole('dialog').style.top).toBe('348px');
|
|
187
|
+
expect(screen.getByRole('dialog').style.left).toBe('24px');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('stays open and repositions on scroll', async () => {
|
|
191
|
+
let top = 100;
|
|
192
|
+
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
|
|
193
|
+
this: HTMLElement
|
|
194
|
+
) {
|
|
195
|
+
const base = {
|
|
196
|
+
top: 0,
|
|
197
|
+
left: 0,
|
|
198
|
+
right: 0,
|
|
199
|
+
bottom: 0,
|
|
200
|
+
width: 0,
|
|
201
|
+
height: 0,
|
|
202
|
+
x: 0,
|
|
203
|
+
y: 0,
|
|
204
|
+
toJSON: () => ({}),
|
|
205
|
+
} as DOMRect;
|
|
206
|
+
if (this.getAttribute('role') === 'dialog') return { ...base, width: 288, height: 180 };
|
|
207
|
+
return { ...base, top, left: 40, width: 160, height: 32 };
|
|
208
|
+
});
|
|
209
|
+
render(<BasicPopover />);
|
|
210
|
+
fireEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
211
|
+
expect(screen.getByRole('dialog').style.top).toBe('140px');
|
|
212
|
+
|
|
213
|
+
top = 60;
|
|
214
|
+
fireEvent.scroll(window);
|
|
215
|
+
await waitFor(() => expect(screen.getByRole('dialog').style.top).toBe('100px'));
|
|
216
|
+
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe('Popover focus and labelling', () => {
|
|
221
|
+
it('restores focus to the trigger on Escape', async () => {
|
|
222
|
+
const user = userEvent.setup();
|
|
223
|
+
render(<BasicPopover />);
|
|
224
|
+
const trigger = screen.getByRole('button', { name: 'Open' });
|
|
225
|
+
await user.click(trigger);
|
|
226
|
+
await waitFor(() => expect(screen.getByRole('dialog')).toBeInTheDocument());
|
|
227
|
+
|
|
228
|
+
await user.keyboard('{Escape}');
|
|
229
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
|
230
|
+
expect(trigger).toHaveFocus();
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('labels the dialog from the trigger', async () => {
|
|
234
|
+
const user = userEvent.setup();
|
|
235
|
+
render(<BasicPopover />);
|
|
236
|
+
const trigger = screen.getByRole('button', { name: 'Open' });
|
|
237
|
+
await user.click(trigger);
|
|
238
|
+
|
|
239
|
+
expect(trigger.id).not.toBe('');
|
|
240
|
+
expect(screen.getByRole('dialog')).toHaveAttribute('aria-labelledby', trigger.id);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('keeps the label valid when the trigger has an explicit id', async () => {
|
|
244
|
+
const user = userEvent.setup();
|
|
245
|
+
render(
|
|
246
|
+
<Popover>
|
|
247
|
+
<PopoverTrigger id="filter-trigger">Open</PopoverTrigger>
|
|
248
|
+
<PopoverContent>Panel</PopoverContent>
|
|
249
|
+
</Popover>
|
|
250
|
+
);
|
|
251
|
+
const trigger = screen.getByRole('button', { name: 'Open' });
|
|
252
|
+
expect(trigger).toHaveAttribute('id', 'filter-trigger');
|
|
253
|
+
|
|
254
|
+
await user.click(trigger);
|
|
255
|
+
expect(screen.getByRole('dialog')).toHaveAttribute('aria-labelledby', 'filter-trigger');
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('does not emit a dangling aria-labelledby without a trigger', async () => {
|
|
259
|
+
render(
|
|
260
|
+
<Popover open>
|
|
261
|
+
<PopoverContent aria-label="Anchored panel">Panel</PopoverContent>
|
|
262
|
+
</Popover>
|
|
263
|
+
);
|
|
264
|
+
const dialog = screen.getByRole('dialog');
|
|
265
|
+
expect(dialog).not.toHaveAttribute('aria-labelledby');
|
|
266
|
+
expect(dialog).toHaveAttribute('aria-label', 'Anchored panel');
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('closes an anchor-only panel on Escape without throwing', async () => {
|
|
270
|
+
const user = userEvent.setup();
|
|
271
|
+
function AnchorOnly() {
|
|
272
|
+
const [open, setOpen] = React.useState(true);
|
|
273
|
+
return (
|
|
274
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
275
|
+
<PopoverAnchor data-testid="anchor">Field</PopoverAnchor>
|
|
276
|
+
<PopoverContent aria-label="Anchored panel">Panel</PopoverContent>
|
|
277
|
+
</Popover>
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
render(<AnchorOnly />);
|
|
281
|
+
await user.keyboard('{Escape}');
|
|
282
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
describe('Popover controlled and interaction edges', () => {
|
|
287
|
+
it('follows a controlled open prop', async () => {
|
|
288
|
+
const { rerender } = render(
|
|
289
|
+
<Popover open>
|
|
290
|
+
<PopoverContent>Panel</PopoverContent>
|
|
291
|
+
</Popover>
|
|
292
|
+
);
|
|
293
|
+
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
|
294
|
+
|
|
295
|
+
rerender(
|
|
296
|
+
<Popover open={false}>
|
|
297
|
+
<PopoverContent>Panel</PopoverContent>
|
|
298
|
+
</Popover>
|
|
299
|
+
);
|
|
300
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('toggles aria-expanded on the trigger', async () => {
|
|
304
|
+
const user = userEvent.setup();
|
|
305
|
+
render(<BasicPopover />);
|
|
306
|
+
const trigger = screen.getByRole('button', { name: 'Open' });
|
|
307
|
+
expect(trigger).toHaveAttribute('aria-expanded', 'false');
|
|
308
|
+
await user.click(trigger);
|
|
309
|
+
expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('does not open from a disabled trigger', async () => {
|
|
313
|
+
const user = userEvent.setup();
|
|
314
|
+
render(
|
|
315
|
+
<Popover>
|
|
316
|
+
<PopoverTrigger disabled>Open</PopoverTrigger>
|
|
317
|
+
<PopoverContent>Panel</PopoverContent>
|
|
318
|
+
</Popover>
|
|
319
|
+
);
|
|
320
|
+
const trigger = screen.getByRole('button', { name: 'Open' });
|
|
321
|
+
expect(trigger).toBeDisabled();
|
|
322
|
+
await user.click(trigger);
|
|
323
|
+
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('stays open when the pointer goes down inside the panel', async () => {
|
|
327
|
+
render(<BasicPopover />);
|
|
328
|
+
fireEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
329
|
+
const dialog = screen.getByRole('dialog');
|
|
330
|
+
|
|
331
|
+
fireEvent.pointerDown(dialog);
|
|
332
|
+
fireEvent.pointerDown(screen.getByRole('button', { name: 'Inner button' }));
|
|
333
|
+
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('repositions on window resize', async () => {
|
|
337
|
+
let top = 100;
|
|
338
|
+
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (
|
|
339
|
+
this: HTMLElement
|
|
340
|
+
) {
|
|
341
|
+
const base = {
|
|
342
|
+
top: 0,
|
|
343
|
+
left: 0,
|
|
344
|
+
right: 0,
|
|
345
|
+
bottom: 0,
|
|
346
|
+
width: 0,
|
|
347
|
+
height: 0,
|
|
348
|
+
x: 0,
|
|
349
|
+
y: 0,
|
|
350
|
+
toJSON: () => ({}),
|
|
351
|
+
} as DOMRect;
|
|
352
|
+
if (this.getAttribute('role') === 'dialog') return { ...base, width: 288, height: 180 };
|
|
353
|
+
return { ...base, top, left: 40, width: 160, height: 32 };
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
render(<BasicPopover />);
|
|
357
|
+
fireEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
358
|
+
expect(screen.getByRole('dialog').style.top).toBe('140px');
|
|
359
|
+
|
|
360
|
+
top = 20;
|
|
361
|
+
fireEvent(window, new Event('resize'));
|
|
362
|
+
await waitFor(() => expect(screen.getByRole('dialog').style.top).toBe('60px'));
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('applies align and collisionPadding to the panel position', () => {
|
|
366
|
+
mockBounds({ top: 100, left: 900, width: 160, height: 32 }, { width: 288, height: 180 });
|
|
367
|
+
render(
|
|
368
|
+
<Popover>
|
|
369
|
+
<PopoverTrigger>Open</PopoverTrigger>
|
|
370
|
+
<PopoverContent align="end" collisionPadding={8}>
|
|
371
|
+
Panel
|
|
372
|
+
</PopoverContent>
|
|
373
|
+
</Popover>
|
|
374
|
+
);
|
|
375
|
+
fireEvent.click(screen.getByRole('button', { name: 'Open' }));
|
|
376
|
+
|
|
377
|
+
// align=end would start at 772; the viewport clamp keeps it at 1024-288-8.
|
|
378
|
+
expect(screen.getByRole('dialog').style.left).toBe('728px');
|
|
379
|
+
});
|
|
380
|
+
});
|