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

Help Center: Align 'X' close button with Help Center icon #94021

Closed
wants to merge 3 commits into from

Conversation

renancarvalho
Copy link
Contributor

Related to https://github.com/Automattic/dotcom-forge/issues/8829
Fixes https://github.com/Automattic/dotcom-forge/issues/8829

Proposed Changes

  • Align the Help Center 'X' with the '?' icon, now it considers the question mark's padding in the alignment.

Why are these changes being made?

Testing Instructions

  • Use live link
  • Make sure when the HC is open, it is aligned like this
image
  • Test also other locations where HC is not placed on the header, for instance my home, it should be positioned as before

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@renancarvalho renancarvalho added the [Feature] Help Center The new integrated Help Center in Calypso that provides support tools on all screens. label Aug 29, 2024
@renancarvalho renancarvalho self-assigned this Aug 29, 2024
@renancarvalho renancarvalho requested a review from a team as a code owner August 29, 2024 09:18
@matticbot matticbot added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Aug 29, 2024
@matticbot
Copy link
Contributor

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • help-center
  • notifications
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug fix/helpcenter_close_button_alignment on your sandbox.

@matticbot
Copy link
Contributor

matticbot commented Aug 29, 2024

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Async-loaded Components (~120 bytes added 📈 [gzipped])

name                               parsed_size           gzip_size
async-load-automattic-help-center       +264 B  (+0.0%)     +120 B  (+0.1%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@arcangelini
Copy link
Contributor

Any chance you would want to account for the left edge also? Now that everything is squared up in the Help Center it would also look nice to have this side too.

Screen Shot 2024-08-29 at 11 54 28

@@ -24,6 +24,10 @@ export const calculateOpeningPosition = ( element: HTMLElement ) => {
return defaultPosition;
}

// This takes into account the '?' button's padding and align the close button with the help center icon
const computedStyle = window.getComputedStyle( element );
Copy link
Member

Choose a reason for hiding this comment

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

FYI, this call is reallly slow. It will typically force style recalc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey 👋 Thank you for the tip. I know it can be relatively slow. Since this happens only when opening help center and is not part of a loop or anything like that, I think this is fine.

Are you concerned about it? I could try other potential solutions, but I am afraid it might bring more complexity.

Copy link
Member

Choose a reason for hiding this comment

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

It happens on every click anywhere on the page when the Help Center is closed :(

It will make every button click slower.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have pushed a new commit that relies on getComputedStyles just once, subsequently, it relies on data-attributes which is faster than getComputedStyles.

I am happy with this approach, but you are welcome to propose another idea :)

Copy link
Member

Choose a reason for hiding this comment

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

That's beautiful! Testing now.

Copy link
Member

@alshakero alshakero left a comment

Choose a reason for hiding this comment

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

The caching idea is perfect! Left some cosmetic comments and found a tiny issue in RTL.

const helpCenterPaddingRight = parseInt( computedStyle.paddingRight, 10 );
const helpCenterIconPaddingRight =
parseInt( element.style.paddingRight, 10 ) ||
parseInt( element.getAttribute( 'data-padding-right' ) || '0', 10 );
Copy link
Member

Choose a reason for hiding this comment

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

You can do element.dataset.paddingRight btw. It automatically covnerts kebab case to camel case.

@@ -36,7 +37,7 @@ export const calculateOpeningPosition = ( element: HTMLElement ) => {
const { x, y, width, height } = element.getBoundingClientRect();

const buttonLeftEdge = x;
const buttonRightEdge = x + width + helpCenterPaddingRight;
const buttonRightEdge = x + width + helpCenterIconPaddingRight;
Copy link
Member

Choose a reason for hiding this comment

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

Would we need to make this - helpCenterIconPaddingRight in RTL?

@@ -24,6 +24,10 @@ export const calculateOpeningPosition = ( element: HTMLElement ) => {
return defaultPosition;
}

// This takes into account the '?' button's padding and align the close button with the help center icon
const computedStyle = window.getComputedStyle( element );
Copy link
Member

Choose a reason for hiding this comment

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

That's beautiful! Testing now.

Comment on lines 103 to 108
// Cache the computed padding-right if not already done
// This will be used to align the help center close button with the "?" icon
if ( ! openingElement.hasAttribute( 'data-padding-right' ) ) {
const computedStyle = window.getComputedStyle( openingElement );
openingElement.setAttribute( 'data-padding-right', computedStyle.paddingRight );
}
Copy link
Member

Choose a reason for hiding this comment

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

This should happen inside calculateOpeningPosition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can move it there, still works fine.
I am, honestly, not sure where is the best place to put this logic. Would you please elaborate a bit more why you believe inside the function is a better place?

Moved.

Copy link
Member

@alshakero alshakero Aug 29, 2024

Choose a reason for hiding this comment

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

Because this value is used in calculateOpeningPosition and useOpeningCoordinates doesn't need it.

@renancarvalho renancarvalho requested a review from a team August 29, 2024 15:15
@renancarvalho
Copy link
Contributor Author

After discussing p1724940421518469/1724923219.497729-slack-C02T4NVL4JJ with team vertex, I have decided to change the approach to addressing this issue, new PR

@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Help Center The new integrated Help Center in Calypso that provides support tools on all screens.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants