Skip to content

ref(alert): Only add onClick listeners to top message portion#33356

Merged
vuluongj20 merged 12 commits into
masterfrom
vl/alert-expand-click
May 3, 2022
Merged

ref(alert): Only add onClick listeners to top message portion#33356
vuluongj20 merged 12 commits into
masterfrom
vl/alert-expand-click

Conversation

@vuluongj20

@vuluongj20 vuluongj20 commented Apr 6, 2022

Copy link
Copy Markdown
Contributor

Currently, if an alert is expandable, we add an onClick event listener on the entire alert. If the expanded alert content contains clickable elements, the click event will propagate to the alert element and close the alert. This is unexpected UX and needs to be fixed.

Screen Shot 2022-04-06 at 11 04 50 AM

This PR refactors the alert component and attaches onClick listeners to the top (unexpanded) portion of the alert. Clicking inside the expanded content no longer closes the alert.

Storybook demo.

@vuluongj20 vuluongj20 requested a review from a team as a code owner April 6, 2022 18:16
<Message>{children}</Message>
{(showExpand || showTrailingItems) && (
<TrailingItemsWrap>
<TrailingItems onClick={e => e.stopPropagation()}>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

stop propagating onClick events that come from elements inside the trailingItems area, since that's where we put buttons and links.

@evanpurkhiser evanpurkhiser Apr 6, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should the <ExpandIcon ... /> live inside the trailing items?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, I want it to be aligned with the other trailing items, like so:
Screen Shot 2022-04-11 at 10 16 08 AM

Comment thread static/app/components/alert.tsx Outdated
const ExpandIcon = styled(IconChevron, {
shouldForwardProp: (p: string) => p !== 'isExpanded',
})<{isExpanded: boolean}>`
transform: ${p => (p.isExpanded ? 'rotate(0deg)' : 'rotate(180deg)')};

@evanpurkhiser evanpurkhiser Apr 6, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👎 use the direction prop on the icon itself

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ahh that's from back when we had more styles than just the transform - totally didn't notice that we could just remove it now. did so in ca2ea1c!

Comment thread static/app/components/alert.tsx Outdated
Comment on lines +182 to +185
padding-top: ${space(1.5)};
padding-bottom: ${space(1.5)};
padding-left: ${space(2)};
padding-right: ${space(1)};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
padding-top: ${space(1.5)};
padding-bottom: ${space(1.5)};
padding-left: ${space(2)};
padding-right: ${space(1)};
padding: ${space(1.5)} ${space(1)} ${space(1.5)} ${space(2)};

🤷 nit

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

most people know the top right bottom left rule

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done! de147ff

))`
transform: ${props => (props.isExpanded ? 'rotate(0deg)' : 'rotate(180deg)')};
justify-self: flex-end;
const TrailingItemsWrap = styled(TrailingItems)`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

any way to get rid of the wrap 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

created two wraps because I wanted to stop event propagation inside <TrailingItems /> (the area containing the two buttons below), but not on IconChevron, which is in <TrailingItemsWrap /> but not in <TrailingItems />.

Screen Shot 2022-04-11 at 10 33 03 AM

so one way to make this simpler is to apply the grid styles to <TrailingItemsWrap />, and then just add display: contents to <TrailingItems />. This way, everything inside <TrailingItems /> will be grid items. Problem with this is that there's only partial support for display: contents in Safari. This is what it looks like in Safari:

Screen Shot 2022-04-11 at 10 38 20 AM

@vuluongj20 vuluongj20 merged commit 21d03ac into master May 3, 2022
@vuluongj20 vuluongj20 deleted the vl/alert-expand-click branch May 3, 2022 22:36
@github-actions github-actions Bot locked and limited conversation to collaborators May 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants