-
Notifications
You must be signed in to change notification settings - Fork 4
fix: Menu and CSSContainerQuery interop
#682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,7 +85,6 @@ export * from './core/checkbox-group' | |
| export * from './core/chip' | ||
| export * from './core/chip-group' | ||
| export * from './core/compact-select-native' | ||
|
Contributor
Author
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. note: now handled by the |
||
| export * from './core/container-query' | ||
| export * from './core/dialog' | ||
| export * from './core/drawer' | ||
| export * from './core/empty-data' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { render } from '@testing-library/react' | ||
| import { CSSContainerQuery } from '../css-container-query' | ||
|
|
||
|
Contributor
Author
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. note: same test as previously implemented, just no |
||
| test('renders correctly and matches snapshot', () => { | ||
| const { asFragment } = render( | ||
| <CSSContainerQuery condition="(max-width: 600px)"> | ||
| <p>Snapshot Test Content</p> | ||
| </CSSContainerQuery>, | ||
| ) | ||
|
|
||
| expect(asFragment()).toMatchSnapshot() | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './css-container-query' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| export * from './breakpoints' | ||
|
Contributor
Author
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. note: export CSS container query, plus other ones that have been missed in recent work. |
||
| export * from './css-container-query' | ||
| export * from './keyboard-navigation' | ||
| export * from './match-media' | ||
| export * from './path' | ||
| export * from './popover' | ||
| export * from './url-search-params' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { getClosestPopoverElement } from '../get-closest-popover-element' | ||
|
|
||
| test('returns the element itself if it has a popover attribute', () => { | ||
| const element = document.createElement('div') | ||
| element.setAttribute('popover', 'auto') | ||
|
|
||
| expect(getClosestPopoverElement(element)).toBe(element) | ||
| }) | ||
|
|
||
| test('returns the closest ancestor with popover attribute', () => { | ||
| const grandparent = document.createElement('div') | ||
| grandparent.setAttribute('popover', 'auto') | ||
|
|
||
| const parent = document.createElement('div') | ||
| const child = document.createElement('div') | ||
|
|
||
| grandparent.appendChild(parent) | ||
| parent.appendChild(child) | ||
|
|
||
| expect(getClosestPopoverElement(child)).toBe(grandparent) | ||
| }) | ||
|
|
||
| test('returns null when no ancestor has popover attribute', () => { | ||
| const parent = document.createElement('div') | ||
| const child = document.createElement('div') | ||
|
|
||
| parent.appendChild(child) | ||
|
|
||
| expect(getClosestPopoverElement(child)).toBeNull() | ||
| }) | ||
|
|
||
| test('works with popover="manual"', () => { | ||
| const element = document.createElement('div') | ||
| element.setAttribute('popover', 'manual') | ||
|
|
||
| expect(getClosestPopoverElement(element)).toBe(element) | ||
| }) | ||
|
|
||
| test('returns the first popover ancestor when multiple exist', () => { | ||
| const outerPopover = document.createElement('div') | ||
| outerPopover.setAttribute('popover', 'auto') | ||
|
|
||
| const innerPopover = document.createElement('div') | ||
| innerPopover.setAttribute('popover', 'manual') | ||
|
|
||
| const child = document.createElement('div') | ||
|
|
||
| outerPopover.appendChild(innerPopover) | ||
| innerPopover.appendChild(child) | ||
|
|
||
| expect(getClosestPopoverElement(child)).toBe(innerPopover) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /** | ||
| * Returns the closest ancestor acting as a popover for the given element. Useful in event | ||
| * handlers when needing to imperatively control the popover from one of its descendants. | ||
| */ | ||
|
Contributor
Author
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. note: new helper function. This is reexported by Menu |
||
| export function getClosestPopoverElement(element: HTMLElement): HTMLElement | null { | ||
| return element.closest('[popover]') | ||
| } | ||
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.
note: make the new helper for menu's available. It's just a reexport of the popover one for now.