[PreviewCard] Create new component#469
Conversation
Netlify deploy preview |
|
What's the reason behind not opening on focus? |
Hovercards (as the name seems to imply) are cards opened only via hover — the interactive content inside is not accessible via keyboard as you might expect if it opened on focus. Ariakit and Mantine don't open theirs on focus, while Radix does however. |
The name is irrelevant, we could change that to whatever. It's the experience that matters. It's not a well-defined pattern, so we can choose to do whatever we think is best.
It's a sighted only UI though right? And opening on focus still benefits sighted users. Non-sighted users don't benefit from the HoverCard at all, whether we open on focus or not? |
The key problem is interactive content inside like a Follow button, there's no way to access that content without focus management if it opens on focus. That's why enforcing it to be hover-only is more appropriate.
It looks like Wikipedia's Hover Cards do open on focus, but you can't access the interactive settings icon inside of it. Maybe it's ok that interactive content is inaccessible to keyboard users, for the benefit of being able to see a preview at all? |
|
|
@colmtuite Why do tooltips have 0 delay but preview cards have the hover's delay when either is triggered on focus? Since both are "secondary", shouldn't they behave the same? |
|
@atomiks Becase PreviewCard almost always goes on a text link, so the popup is not necessarily desired when you focus it. Whereas Tooltip almost always goes on an icon button, and you might need to know what the button does asap. Also, PreviewCard is almost always very significantly larger than Tooltip, so it is extremely obnoxious when it instantly appears upon focusing its trigger. The Tooltip is much less obnoxious. |
Couldn't the same argument be applied to a link, if the text can be as ambiguous as an icon button? In some circumstances you may want to preview of the link's contents as soon as possible as well. Instagram's preview cards have 0 delay, but Wikipedia's have the delay. I think I do prefer Wikipedia's method (that you're suggesting) because of your next point:
The cards on Instagram can block a lot of content so this makes more sense to me. An API change to configure hover + focus delay triggers individually may be a bit problematic. I think we can leave the configuration for this for now, and have the delay be applied equally to hover + focus triggers. |
I think it's possible that we don't ever need to configure the triggers independently. But this is a good first step in any case. 👍 |
| const { delayType = 'rest', delay, closeDelay, animated = true } = props; | ||
|
|
||
| const delayWithDefault = delay ?? OPEN_DELAY; | ||
| const closeDelayWithDefault = closeDelay ?? CLOSE_DELAY; |
There was a problem hiding this comment.
| const { delayType = 'rest', delay, closeDelay, animated = true } = props; | |
| const delayWithDefault = delay ?? OPEN_DELAY; | |
| const closeDelayWithDefault = closeDelay ?? CLOSE_DELAY; | |
| const { delayType = 'rest', delay = OPEN_DELAY, closeDelay = CLOSE_DELAY, animated = true } = props; |
Why not use the destructuring for assigning the defaults?
There was a problem hiding this comment.
The prop-types/docs api gen doesn't allow variables as defaults when destructuring
There was a problem hiding this comment.
Damn, I am adding it on the code-infra topics for next week.
| * The side of the anchor element that the preview card element should align to. | ||
| * @default 'bottom' | ||
| */ | ||
| side?: Side; |
There was a problem hiding this comment.
I think we should use rtl safe values here, like start/end. I know the type comes from Floating UI, but we can change the values on a component level.
There was a problem hiding this comment.
For example, for alignment, we use: start, center, and end. We would be consistent.
There was a problem hiding this comment.
You're right that we can support logical sides on a component level, but they are more complex to understand compared to physical sides, and logical alignments are far more useful for many cases, not only RTL. This is an issue for the anchor positioning hook though, so it shouldn't relate to this PR itself.
packages/mui-base/src/PreviewCard/Backdrop/usePreviewCardBackdrop.types.ts
Show resolved
Hide resolved
michaldudak
left a comment
There was a problem hiding this comment.
Looks good overall. I have a few minor remarks.
| className, | ||
| ownerState, | ||
| extraProps: otherProps, | ||
| customStyleHookMapping: { |
There was a problem hiding this comment.
This could be extracted to a const outside of the component so it's not recreated on every render
There was a problem hiding this comment.
I noticed our other components have it inlined sometimes, and useComponentRenderer passes it as a memo dependency, so they'll need to be updated as well
Closes #451