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

refactor: Reusable internal drag handle #3152

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

pan-kot
Copy link
Member

@pan-kot pan-kot commented Dec 23, 2024

Description

Reusing drag handle between collection prefs, split panel, and drawers with potential future extension to board components, see: [a3UOAhaNX7KH].

How has this been tested?

  • New unit tests for drag handle
  • Screenshot tests
Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pan-kot pan-kot force-pushed the internal-drag-handle branch from b0e8100 to 35a4185 Compare December 23, 2024 08:21
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.41%. Comparing base (d0ecb9a) to head (8f367ef).
Report is 13 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #3152    +/-   ##
========================================
  Coverage   96.40%   96.41%            
========================================
  Files         784      784            
  Lines       22136    22165    +29     
  Branches     7592     7203   -389     
========================================
+ Hits        21341    21370    +29     
  Misses        788      788            
  Partials        7        7            

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

@pan-kot pan-kot force-pushed the internal-drag-handle branch from c5b4123 to 4f1bd4e Compare December 24, 2024 10:56
@pan-kot pan-kot marked this pull request as ready for review December 24, 2024 13:13
@pan-kot pan-kot requested a review from a team as a code owner December 24, 2024 13:13
@pan-kot pan-kot requested review from Al-Dani and removed request for a team December 24, 2024 13:13
reactEvent: React.KeyboardEvent
) {
if (!handler) {
return;
Copy link
Member

Choose a reason for hiding this comment

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

nice!

Copy link
Member

Choose a reason for hiding this comment

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

What's nice here, if the same check already happened on the line 71 anyway?

Copy link
Member

Choose a reason for hiding this comment

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

true, but there are some occurrences of handler && fireKeyboardEvent(onKeyDown..) across the codebase. All other fire.*Event have this check built-in, so why not align this method too?

Copy link
Member

Choose a reason for hiding this comment

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

Making it optional is nice. Duplicating already existing check is not

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch - I will remove the unneeded if statement 👍

ref: React.Ref<DragHandleProps.Ref>
) => {
const dragHandleRefObject = useRef<HTMLElement>(null);
const dragHandleRef = useMergeRefs(dragHandleRefObject);
Copy link
Member

Choose a reason for hiding this comment

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

what do we merging here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! There was the dragHandleRef originally but I had to replace it with the combination of the ref object and ref to use the useForwardFocus. While it is a common strategy in most components, the drag handle is still internal and does not feature the __internalRootRef - I will update it to only keep the ref object for now.

@@ -9,7 +9,8 @@ export interface Focusable {
export interface FocusControlRefs {
toggle: RefObject<Focusable>;
close: RefObject<Focusable>;
slider: RefObject<HTMLDivElement>;
slider: RefObject<Focusable>;
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to refs now? I see slider ref is used to focus on it inside Split panel. Can we instead use handle ref?

Copy link
Member Author

Choose a reason for hiding this comment

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

I prepare the drag handle component to become a public component. Similar to other similar components, it does not give access to the dom node via ref but only allows to cast the focus programmatically - that is what the slider ref is used for.

The handle ref is a custom div wrapper around the drag handle to get the placement information from.

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.

3 participants