Skip to content

Commit

Permalink
fix: update event handlers to call stopPropagation
Browse files Browse the repository at this point in the history
otherwise, with React 17's changes to event delegation, the event
handlers that the newly mounted components set up in `componentDidMount`
would fire immediately, immediately dismissing the component again
  • Loading branch information
marcelgerber committed Nov 7, 2023
1 parent 080c15e commit 4a9a2a1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
5 changes: 4 additions & 1 deletion adminSiteClient/EditableTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ export class EditableTags extends React.Component<{
)}
<button
className="btn btn-link EditableTags__action"
onClick={this.onToggleEdit}
onClick={(e) => {
this.onToggleEdit()
e.stopPropagation()
}}
>
<FontAwesomeIcon icon={faEdit} />
Edit
Expand Down
14 changes: 8 additions & 6 deletions packages/@ourworldindata/grapher/src/controls/ActionButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,10 @@ export class ActionButtons extends React.Component<{
dataTrackNote="chart_click_download"
showLabel={this.showButtonLabels}
icon={faDownload}
onClick={action(
() =>
(this.manager.isDownloadModalOpen =
true)
)}
onClick={(e) => {

Check warning on line 251 in packages/@ourworldindata/grapher/src/controls/ActionButtons.tsx

View workflow job for this annotation

GitHub Actions / eslint

Missing return type on function
this.manager.isDownloadModalOpen = true
e.stopPropagation()
}}
style={{ width: "100%" }}
/>
</li>
Expand All @@ -264,7 +263,10 @@ export class ActionButtons extends React.Component<{
dataTrackNote="chart_click_share"
showLabel={this.showButtonLabels}
icon={faShareNodes}
onClick={this.toggleShareMenu}
onClick={(e) => {

Check warning on line 266 in packages/@ourworldindata/grapher/src/controls/ActionButtons.tsx

View workflow job for this annotation

GitHub Actions / eslint

Missing return type on function
this.toggleShareMenu()
e.stopPropagation()
}}
isActive={this.manager.isShareMenuActive}
style={{ width: "100%" }}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ export class EntitySelectionToggle extends React.Component<{
<div className="entity-selection-menu">
<button
className={classnames("menu-toggle", { active })}
onClick={(): void => {
onClick={(e): void => {
this.props.manager.isSelectingData = !active
e.stopPropagation()
}}
data-track-note="chart_add_entity"
>
Expand Down
3 changes: 2 additions & 1 deletion packages/@ourworldindata/grapher/src/controls/ShareMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ export class ShareMenu extends React.Component<ShareMenuProps, ShareMenuState> {
document.removeEventListener("click", this.onClickSomewhere)
}

@action.bound onEmbed(): void {
@action.bound onEmbed(e: React.MouseEvent): void {
const { canonicalUrl, manager } = this
if (!canonicalUrl) return
manager.isEmbedModalOpen = true
this.dismiss()
e.stopPropagation()
}

@action.bound async onNavigatorShare(): Promise<void> {
Expand Down
3 changes: 2 additions & 1 deletion packages/@ourworldindata/grapher/src/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ export class Footer<
<a
className="learn-more-about-data"
data-track-note="chart_click_sources"
onClick={action(() => {
onClick={action((e) => {
e.stopPropagation()
// if embbedded, open the sources modal
if (this.manager.isEmbeddedInAnOwidPage) {
this.manager.isSourcesModalOpen = true
Expand Down

0 comments on commit 4a9a2a1

Please sign in to comment.