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

WRR-6380: Converted Popup/Popup to functional component #1734

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from

Conversation

ion-andrusciac-lgp
Copy link
Contributor

@ion-andrusciac-lgp ion-andrusciac-lgp commented Oct 25, 2024

Checklist

  • I have read and understand the contribution guide
  • A CHANGELOG entry is included
  • At least one test case is included for this feature or bug fix
  • Documentation was added or is not needed
  • This is an API breaking change

Issue Resolved / Feature Added

At this moment, Popup/Popup is based on a class component. The goal is to convert it to a functional component.

Resolution

Converted Popup/Popup to functional component

Additional Considerations

Links

WRR-6380

Comments

Enact-DCO-1.0-Signed-off-by: Ion Andrusciac [email protected]

Copy link

codecov bot commented Oct 25, 2024

Codecov Report

Attention: Patch coverage is 86.13861% with 14 lines in your changes missing coverage. Please review.

Project coverage is 80.83%. Comparing base (067a69b) to head (5b0556d).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
Popup/Popup.js 86.13% 12 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1734      +/-   ##
===========================================
+ Coverage    80.81%   80.83%   +0.02%     
===========================================
  Files          148      148              
  Lines         6681     6695      +14     
  Branches      1986     1987       +1     
===========================================
+ Hits          5399     5412      +13     
- Misses         973      974       +1     
  Partials       309      309              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Popup/Popup.js Outdated Show resolved Hide resolved
Popup/Popup.js Outdated
Comment on lines 311 to 312
const containerId = useRef(Spotlight.add());
const paused = useRef(new Pause('Popup'));
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need useRef or an useMemo can be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

useMemo can be used but useRef is also a good option because I just need to keep a reference that persists across re-renders

const handleComponentUpdate = useCallback(() => {
if (open !== prevOpen) {
if (!noAnimation) {
if (!open && popupOpen === OpenState.OPENING || !open && popupOpen === OpenState.OPEN) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain why this changed from using popupOpen === OpenState.CLOSED ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

with the current implementation and async state change of the popupOpen, if we use popupOpen === OpenState.CLOSED, the spotlight navigation will not be resumed when the popup is open and closed quickly


// if there is no currently-spotted control or it is wrapped by the popup's container, we
// know it's safe to change focus
if (!current || (containerNode && containerNode.contains(current))) {
// attempt to set focus to the activator, if available
if (!Spotlight.isPaused()) {
if (!Spotlight.isPaused() || !paused.current.isPaused()) {
Copy link
Contributor

@daniel-stoian-lgp daniel-stoian-lgp Oct 30, 2024

Choose a reason for hiding this comment

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

why was this additional condition needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this additional condition, the activator (component that opened the Popup) will be focused after the Popup is closed when it's used in other components like Input

Popup/Popup.js Outdated Show resolved Hide resolved
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.

2 participants