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

Add popover=hint example #295

Merged
merged 9 commits into from
Feb 13, 2025
Merged

Conversation

chrisdavidmills
Copy link
Contributor

@chrisdavidmills chrisdavidmills commented Feb 6, 2025

This PR adds a demo to demonstrate typical usage of the popover="hint" attribute value, which is supported in Chrome 133.

@chrisdavidmills chrisdavidmills requested a review from a team as a code owner February 6, 2025 13:22
@chrisdavidmills chrisdavidmills requested review from pepelsbey and removed request for a team February 6, 2025 13:22
@chrisdavidmills chrisdavidmills marked this pull request as draft February 6, 2025 13:22
}

#submenu-1 {
position-anchor: --menu-anchor-1;
Copy link

Choose a reason for hiding this comment

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

You shouldn't need to add position-anchor or anchor-name to anything in these demos, if you just add showPopover({source: invoker}) to the JS bit. Declarative popovertarget activation automatically creates an implicit anchor reference, as does using source in showPopover().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mfreed7 Nice! That works like a charm. Updated.

QQ: We don't actually have the show option documented on MDN. I'm going to add it in the PR associated with this demo, but I should also add a compat data entry for it at some point. When was show first supported?

Copy link

Choose a reason for hiding this comment

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

Great! Yeah, I think that's an outstanding item: mdn/mdn#598. It's been shipped in Chromium since M133.

Copy link

@mfreed7 mfreed7 left a comment

Choose a reason for hiding this comment

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

Demo looks good to me!

@chrisdavidmills chrisdavidmills marked this pull request as ready for review February 12, 2025 13:44
@chrisdavidmills
Copy link
Contributor Author

@bsmth are you OK to have a look at this one? Alternatively, @pepelsbey might enjoy reviewing it ;-)

[popover="hint"] {
inset: unset;
position: absolute;
top: calc(anchor(bottom) + 5px);
Copy link
Member

Choose a reason for hiding this comment

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

Only issue I have with this is that it looks weird on browsers that don't support it, you get a tooltip off the bottom of the page and some scrollbars on mouseover. It looks like it's hard to do proper feature detection on that level of granularity (specifically ~supports popover = hint), isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could feature detect based on the popover property of the DOM element, but it'd be a right pain building an alternative that still provides an acceptable experience in non-supporting browsers. What do think is needed here?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I figured as much. I'm not sure what the best option is, maybe a note somewhere about browser compat (in the readme where we link to it)? At least that we flag it's a known thing in browsers that don't support it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I've added in a note about browser support, and added in a media query to stop the note box from covering the button bar on narrow screens

README.md Outdated Show resolved Hide resolved
Copy link
Member

@bsmth bsmth left a comment

Choose a reason for hiding this comment

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

Thanks, Chris!

@bsmth bsmth merged commit 773e0af into mdn:main Feb 13, 2025
1 check passed
@chrisdavidmills chrisdavidmills deleted the add-popover=hint-example branch February 13, 2025 10:57
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.

3 participants