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

fix: Fix PlaygroundEditor preventing scroll when not focused #974

Merged
merged 1 commit into from
Jan 5, 2022

Conversation

diegohaz
Copy link
Member

@diegohaz diegohaz commented Jan 3, 2022

Right now, we can't scroll the playground editor when it's expanded, but not focused (which in the code is translated into the editable local state).

This has been an annoying experience. So this PR fixes the behavior so the editor doesn't need to be focused anymore to be scrollable.

How to test

  1. Open https://ariakit.org/examples/combobox
  2. Expand the editor
  3. Focus on something else
  4. Try to scroll on the editor

And then repeat the same with this PR preview site (https://ariakit-git-fix-playground-editor-scrolling-ariakit.vercel.app/examples/combobox)

@vercel
Copy link

vercel bot commented Jan 3, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

ariakit – ./

🔍 Inspect: https://vercel.com/ariakit/ariakit/4kBtsDCaaXVpgmhQo1H5u379cq72
✅ Preview: https://ariakit-git-fix-playground-editor-scrolling-ariakit.vercel.app

reakit – ./

🔍 Inspect: https://vercel.com/ariakit/reakit/3bwPdcV8SxyedpHpxb23a7JQNQEX
✅ Preview: Canceled

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 3, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@codecov
Copy link

codecov bot commented Jan 3, 2022

Codecov Report

Merging #974 (ba3b9f4) into v2 (0f31bf6) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##               v2     #974   +/-   ##
=======================================
  Coverage   62.63%   62.63%           
=======================================
  Files         159      159           
  Lines        4129     4129           
  Branches     1159     1159           
=======================================
  Hits         2586     2586           
  Misses       1542     1542           
  Partials        1        1           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f31bf6...ba3b9f4. Read the comment docs.

@@ -212,7 +212,7 @@ export type PlaygroundCodeOptions<T extends As = "div"> = Options<T> & {
maxHeight?: number;
disclosureProps?: ButtonProps<ElementType>;
expanded?: boolean;
setExpanded?: SetState<boolean>;
setExpanded?: (expanded: boolean) => void;
Copy link
Member Author

Choose a reason for hiding this comment

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

Changing this type so it doesn't need to be a state updater function similar to the one returned by React's useState. That is, people can pass any stable or non-stable function that accepts a boolean value.

Comment on lines +141 to +146
const [expanded, setExpanded] = useControlledState(
defaultExpanded ?? !maxHeight,
expandedProp,
setExpandedProp
);

Copy link
Member Author

Choose a reason for hiding this comment

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

Defining the state here so we can access the expanded state in the PlaygroundEditor component. PlaygroundEditor uses PlaygroundCode underneath and extends its prop types. Since PlaygroundEditor can also receive the expanded props, we're doing the same thing here as in the PlaygroundEditor component.

@@ -241,7 +251,7 @@ export const usePlaygroundEditor = createHook<PlaygroundEditorOptions>(
if (event.defaultPrevented) return;
setFocusVisible(true);
},
[onFocusVisibleProp, editable]
[onFocusVisibleProp]
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a cleanup. Not sure why this was here.

Copy link
Member

@saideepesh000 saideepesh000 left a comment

Choose a reason for hiding this comment

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

👍

@diegohaz diegohaz merged commit 4831ab8 into v2 Jan 5, 2022
@diegohaz diegohaz deleted the fix/playground-editor-scrolling branch January 5, 2022 13:49
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.

None yet

3 participants