-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Popover): use native Popover API and CSS refinements (#2369)
## Uses Popover API - This fixes tab/keyboard navigation out of the box, meaning if you trigger a popover, press tab, the focus will enter the popover element regardless of DOM structure - This fixes z-index issues when paired with i.e. dialog, meaning we do not need the `portal` concept anymore - This simplifies the API meaning we can use `popovertarget="ID"` on any element - aligning our API with HTML standards and becoming very similar when going framework independent in the future - Older iOS versions does not support popover API, so maybe we should ship with [the polyfill](https://github.com/oddbird/popover-polyfill) in our project for now so we can provide 100% support and just remove the polyfill when iOS 16.7 is "deaderer"? :D ## Arrow is drawn with pseudo-element - This makes `:first-child` and `:last-child` CSS selectors work as expected - This makes it easier to make popover elements in the future when making web components - floating-ui does not support this out of the box, but is easy to fix with a simple custom middleware --------- Co-authored-by: Tobias Barsnes <[email protected]>
- Loading branch information
1 parent
6ae7cc4
commit 48f5713
Showing
18 changed files
with
552 additions
and
650 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,9 @@ | ||
--- | ||
"@digdir/designsystemet-css": patch | ||
"@digdir/designsystemet-react": patch | ||
--- | ||
|
||
Popover: | ||
- Rename `<Popover.Root>` to `<Popover.Context>` | ||
- use Popover API, allowing `<Popover>` to be used without `Popover.Context` | ||
- Remove `portal` prop |
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 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 |
---|---|---|
@@ -1,84 +1,76 @@ | ||
.ds-popover { | ||
--dsc-popover-border: 1px solid; | ||
--dsc-popover-arrow-size: var(--ds-spacing-2); | ||
--dsc-popover-background: var(--ds-color-neutral-background-default); | ||
--dsc-popover-border-radius: min(1rem, var(--ds-border-radius-md)); | ||
--dsc-popover-border: 1px solid var(--ds-color-neutral-border-default); | ||
--dsc-popover-color: var(--ds-color-neutral-text-default); | ||
--dsc-popover-border-color: var(--ds-color-neutral-border-default); | ||
--dsc-popover-padding: var(--ds-spacing-3); | ||
--dsc-popover-max-width: 300px; | ||
--dsc-popover-border-radius: min(1rem, var(--ds-border-radius-md)); | ||
--dsc-popover-padding: var(--ds-spacing-3) var(--ds-spacing-4); | ||
|
||
z-index: 1500; | ||
background: var(--dsc-popover-background); | ||
color: var(--dsc-popover-color); | ||
padding: var(--dsc-popover-padding); | ||
border: var(--dsc-popover-border); | ||
border-radius: var(--dsc-popover-border-radius); | ||
border-color: var(--dsc-popover-border-color); | ||
border: var(--dsc-popover-border); | ||
box-sizing: border-box; | ||
color: var(--dsc-popover-color); | ||
inset: 0 auto auto 0; | ||
max-width: var(--dsc-popover-max-width); | ||
} | ||
|
||
.ds-popover--sm { | ||
--dsc-popover-padding: var(--ds-spacing-2) var(--ds-spacing-3); | ||
} | ||
|
||
.ds-popover--md { | ||
--dsc-popover-padding: var(--ds-spacing-3) var(--ds-spacing-4); | ||
} | ||
overflow: visible; | ||
padding: var(--dsc-popover-padding); | ||
position: fixed; | ||
|
||
.ds-popover--lg { | ||
--dsc-popover-padding: var(--ds-spacing-3) var(--ds-spacing-5); | ||
} | ||
&::before { | ||
background: var(--dsc-popover-background); | ||
border: inherit; | ||
border-left-color: transparent; | ||
border-top-color: transparent; | ||
box-sizing: border-box; | ||
content: ''; | ||
height: var(--dsc-popover-arrow-size); | ||
left: var(--ds-popover-arrow-x); | ||
position: absolute; | ||
top: var(--ds-popover-arrow-y); | ||
translate: -50% -50%; | ||
width: var(--dsc-popover-arrow-size); | ||
} | ||
|
||
.ds-popover--default { | ||
--dsc-popover-background: var(--ds-color-neutral-background-default); | ||
--dsc-popover-border-color: var(--ds-color-neutral-border-default); | ||
--dsc-popover-color: var(--ds-color-neutral-text-default); | ||
} | ||
|
||
.ds-popover--info { | ||
--dsc-popover-background: var(--ds-color-info-surface-default); | ||
--dsc-popover-border-color: var(--ds-color-info-border-default); | ||
--dsc-popover-color: var(--ds-color-info-text-default); | ||
} | ||
&[data-size="sm"] { --dsc-popover-padding: var(--ds-spacing-2) var(--ds-spacing-3) } | ||
&[data-size="lg"] { --dsc-popover-padding: var(--ds-spacing-3) var(--ds-spacing-5) } | ||
|
||
.ds-popover--warning { | ||
--dsc-popover-background: var(--ds-color-warning-surface-default); | ||
--dsc-popover-border-color: var(--ds-color-warning-border-default); | ||
--dsc-popover-color: var(--ds-color-warning-text-default); | ||
} | ||
&[data-placement="top"]::before { | ||
top: 100%; | ||
rotate: 45deg; | ||
} | ||
|
||
.ds-popover--danger { | ||
--dsc-popover-background: var(--ds-color-danger-surface-default); | ||
--dsc-popover-border-color: var(--ds-color-danger-border-default); | ||
--dsc-popover-color: var(--ds-color-danger-text-default); | ||
} | ||
&[data-placement="left"]::before { | ||
left: 100%; | ||
rotate: -45deg; | ||
} | ||
|
||
.ds-popover__arrow { | ||
position: absolute; | ||
background: var(--dsc-popover-background); | ||
transform: rotate(45deg); | ||
} | ||
&[data-placement="right"]::before { | ||
left: 0; | ||
rotate: 135deg; | ||
} | ||
|
||
.ds-popover__arrow.ds-popover__arrow--top { | ||
border-top: var(--dsc-popover-border); | ||
border-left: var(--dsc-popover-border); | ||
border-color: inherit; | ||
} | ||
&[data-placement="bottom"]::before { | ||
top: 0; | ||
rotate: -135deg; | ||
} | ||
|
||
.ds-popover__arrow.ds-popover__arrow--bottom { | ||
border-bottom: var(--dsc-popover-border); | ||
border-right: var(--dsc-popover-border); | ||
border-color: inherit; | ||
} | ||
&[data-variant="info"] { | ||
--dsc-popover-background: var(--ds-color-info-surface-default); | ||
--dsc-popover-border: 1px solid var(--ds-color-info-border-default); | ||
--dsc-popover-color: var(--ds-color-info-text-default); | ||
} | ||
|
||
.ds-popover__arrow.ds-popover__arrow--right { | ||
border-top: var(--dsc-popover-border); | ||
border-right: var(--dsc-popover-border); | ||
border-color: inherit; | ||
} | ||
&[data-variant="warning"] { | ||
--dsc-popover-background: var(--ds-color-warning-surface-default); | ||
--dsc-popover-border: 1px solid var(--ds-color-warning-border-default); | ||
--dsc-popover-color: var(--ds-color-warning-text-default); | ||
} | ||
|
||
.ds-popover__arrow.ds-popover__arrow--left { | ||
border-bottom: var(--dsc-popover-border); | ||
border-left: var(--dsc-popover-border); | ||
border-color: inherit; | ||
&[data-variant="danger"] { | ||
--dsc-popover-background: var(--ds-color-danger-surface-default); | ||
--dsc-popover-border: 1px solid var(--ds-color-danger-border-default); | ||
--dsc-popover-color: var(--ds-color-danger-text-default); | ||
} | ||
} |
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 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 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
Oops, something went wrong.