Skip to content
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

feat(Popover): add utility class for inline text #2915

Merged
merged 8 commits into from
Dec 19, 2024
Merged

Conversation

Barsnes
Copy link
Member

@Barsnes Barsnes commented Dec 18, 2024

resolves #2781

Copy link

changeset-bot bot commented Dec 18, 2024

🦋 Changeset detected

Latest commit: ae07913

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@digdir/designsystemet-css Patch
@digdir/designsystemet-react Patch
@digdir/designsystemet Patch
@digdir/designsystemet-theme Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Dec 18, 2024

Preview deployments for this pull request:

Storybook - 19. Dec 2024 - 09:44

@Barsnes Barsnes marked this pull request as ready for review December 18, 2024 07:26
Copy link
Contributor

github-actions bot commented Dec 18, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 55.2% 3198 / 5793
🔵 Statements 55.2% 3198 / 5793
🔵 Functions 86.6% 181 / 209
🔵 Branches 76.96% 518 / 673
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/react/src/components/Popover/PopoverTrigger.tsx 85% 25% 100% 85% 29-31
Generated in workflow #1351 for commit ae07913 by the Vitest Coverage Report Action

<Paragraph>
Vi bruker{' '}
<Popover.Trigger asChild>
<button className='ds-popover--trigger-inline'>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Burde vi legge på type="button" i eksempel så folk ikke glemmer å endre på dette? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tenker du at klassen kun targeter type="button"? Det er kanskje ikkje så dumt 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nei :) Bare at button automatisk er type="submit" om man ikke setter type="button", så det kan fort bli accidental submit om de har en popup-tekstforklaring inni et skjema og glemmer type="button" ☺️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right sikkert lurt, kanskje klassen også skulle ha sjekka det - slik at me kan være meir sikre på at dei bruker det rett 🤔

@@ -55,3 +55,13 @@
--dsc-popover-background: var(--ds-color-neutral-background-default);
}
}

.ds-popover--trigger-inline {
Copy link
Collaborator

@mimarz mimarz Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could be data attribute (data-inline) to match the rest of our css where we use that for our modifiers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice if this specifies that it is for popover 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Godt poeng! hva med:

[data-popover="inline"] {
  ...
}

Copy link
Collaborator

@mimarz mimarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we add a inline prop to our Popover.Trigger to toggle data-inline?

@Barsnes
Copy link
Member Author

Barsnes commented Dec 18, 2024

How about we add a inline prop to our Popover.Trigger to toggle data-inline?

I'm not sure how well this plays with asChild. We would need to look something like this:

const Component = asChild ? Slot : (inline ? Button : 'button');

return <Component ref={ref} popovertarget={popoverId} {...rest} />;

Which looks weird to me

Since we use all: unset, we run into problems with other classes being used on the same element as well, so it's safer for us to make the user have to create a new element.

I think it is better to ask our users to asChild this onto a plain button.

This is an image of what happens when I put the class directly on the trigger.
image

@eirikbacker
Copy link
Contributor

How about we add a inline prop to our Popover.Trigger to toggle data-inline?

I'm not sure how well this plays with asChild. We would need to look something like this:

const Component = asChild ? Slot : (inline ? Button : 'button');

return <Component ref={ref} popovertarget={popoverId} {...rest} />;

Which looks weird to me

Since we use all: unset, we run into problems with other classes being used on the same element as well, so it's safer for us to make the user have to create a new element.

Hi! I disagree - it is easier to add a attribute than making the user add children and remembering correct button type etc.
all: unset is not the issue here, it is the specificity of :not([hidden]) in button.css, which actually should be corrected since this is a tweak of the default display, meaning it should be at the same specificity as user agent styles anyway.

If you change:

  &:not([hidden]) {
    display: flex;
  }

in button.css, to:

  /* Using :where as this should be as easy to overwrite as user agent styles */
  &:where(:not([hidden])) {
    display: flex;
  }

it works smoothly :)

@Barsnes
Copy link
Member Author

Barsnes commented Dec 19, 2024

How about we add a inline prop to our Popover.Trigger to toggle data-inline?

I'm not sure how well this plays with asChild. We would need to look something like this:

const Component = asChild ? Slot : (inline ? Button : 'button');

return <Component ref={ref} popovertarget={popoverId} {...rest} />;

Which looks weird to me
Since we use all: unset, we run into problems with other classes being used on the same element as well, so it's safer for us to make the user have to create a new element.

Hi! I disagree - it is easier to add a attribute than making the user add children and remembering correct button type etc. all: unset is not the issue here, it is the specificity of :not([hidden]) in button.css, which actually should be corrected since this is a tweak of the default display, meaning it should be at the same specificity as user agent styles anyway.

If you change:

  &:not([hidden]) {
    display: flex;
  }

in button.css, to:

  /* Using :where as this should be as easy to overwrite as user agent styles */
  &:where(:not([hidden])) {
    display: flex;
  }

it works smoothly :)

Sure, but we still get hover and active styles..
image

If we do the proposed solution above, with changing the rendered element, this is not an issue, though - but then your proposed fix is not an issue either.

Copy link
Collaborator

@mimarz mimarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@Barsnes Barsnes merged commit eb3f58b into next Dec 19, 2024
10 checks passed
@Barsnes Barsnes deleted the popover/text-class branch December 19, 2024 09:31
Barsnes pushed a commit that referenced this pull request Jan 8, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to next, this PR will
be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`next` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `next`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @digdir/[email protected]

### Minor Changes

- Fix wrong base default color beeing set by the themebuilder
([#2953](#2953))

- Moved typography based sizing formula to design-tokens
([#2796](#2796))

- Removed design-tokens `sizing` & `spacing`, use `size`.
([#2939](#2939))

- Support for building typography based sizing design-tokens
([#2796](#2796))

### Patch Changes

- Rename `data-ds-typography` to `data-typography`
([#2959](#2959))

## @digdir/[email protected]

### Minor Changes

- Removed CSS variables `--ds-spacing-*` & `--ds-sizing-*`, use
`--ds-size-*`.
([#2939](#2939))

- New CSS variables for sizes, `--ds-size-*`
([#2935](#2935))

- Moved typography based sizing formula to design-tokens
([#2796](#2796))

### Patch Changes

- Button: add `height: fit-content`
([#2942](#2942))

- Pagination: Use empty `li` for ellipsis
([#2942](#2942))

- Link: Fix missing underline when using Tailwind
([#2923](#2923))

-   Table: ([#2933](#2933))

    -   Correct footer styling
    -   Automatic focus styling for sorting buttons

- Switch: Adjust design to better align with radio and checkbox
([#2929](#2929))

- Tooltip: Use popover API
([#2916](#2916))

    -   Removes `delay`, this is now `--dsc-tooltip-transition-delay`
    -   Removes `defaultOpen`
    -   Removes `portal`
    -   Removes ability to hover to keep open

- PopoverTrigger: New prop `inline` for use when inline elements (such
as text) need a `Popover`
([#2915](#2915))

## @digdir/[email protected]

### Minor Changes

- Removed CSS variables `--ds-spacing-*` & `--ds-sizing-*`, use
`--ds-size-*`.
([#2939](#2939))

- Moved typography based sizing formula to design-tokens
([#2796](#2796))

- Removed design-tokens `sizing` & `spacing`, use `size`.
([#2939](#2939))

### Patch Changes

- Rename `data-ds-typography` to `data-typography`
([#2959](#2959))

## @digdir/[email protected]

### Patch Changes

- Pagination: Use empty `li` for ellipsis
([#2942](#2942))

- Add missing `data-size` and `data-color` props to Details
([#2930](#2930))

-   Table: ([#2933](#2933))

    -   Correct footer styling
    -   Automatic focus styling for sorting buttons

- Loosen default types for `data-color` and `data-size` to support
accept `string`
([#2951](#2951))

- Export all utilities
([#2961](#2961))

- Field: Fix `position` not working
([#2931](#2931))

- Tooltip: Use popover API
([#2916](#2916))

    -   Removes `delay`, this is now `--dsc-tooltip-transition-delay`
    -   Removes `defaultOpen`
    -   Removes `portal`
    -   Removes ability to hover to keep open

- PopoverTrigger: New prop `inline` for use when inline elements (such
as text) need a `Popover`
([#2915](#2915))

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Popover design for popovers in in text
3 participants