Skip to content

Enhancement: Makes usePreventScroll controllable. #972

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

Merged
merged 4 commits into from
Sep 11, 2020

Conversation

McZenith
Copy link
Contributor

@McZenith McZenith commented Aug 16, 2020

Closes #889

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@McZenith McZenith changed the title fixed default parameter issue Enhancement: Makes usePreventScroll controllable. Aug 16, 2020
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Just a couple of suggestions that should fix the tests, lemme know if they make sense

isOpen?: boolean
}

export function usePreventScroll(options? : PreventScrollOptions) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export function usePreventScroll(options? : PreventScrollOptions) {
export function usePreventScroll(options? : PreventScrollOptions = {}) {

Adding the above would make it so you can properly attempt to deconstruct isOpen even when options is undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @LFDanLu! I was getting an error (How do I fix error TS1015: Parameter cannot have question mark and initializer?
). However, i stumbled upon this (https://stackoverflow.com/questions/17186566/how-do-i-fix-error-ts1015-parameter-cannot-have-question-mark-and-initializer) and it is all resolved now.


export function usePreventScroll(options? : PreventScrollOptions) {

const {isOpen = false} = options;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const {isOpen = false} = options;
const {isOpen = true} = options;

IMO this should be flipped to true so that pre-existing components will continue to work if they call usePreventScroll without any arguments.

Copy link
Member

Choose a reason for hiding this comment

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

In the issue I suggested this function usePreventScroll(options?: PreventScrollOptions = {isOpen: true}). Then, if the options aren't given, we default to true (as we do today), but if the options are given, we default to false to match expected behavior based on prop name. Too weird?

Copy link
Member

Choose a reason for hiding this comment

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

that sounds fine but isn't that essentially what the above change is doing?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see the difference now (thanks @snowystinger). IMO it feels a bit weird that we would have two different defaults dependent on whether or not options are provided or not. Is there a use case you had in mind?

Copy link
Member

Choose a reason for hiding this comment

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

Just backward compatibility really...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello! I'm going to work on this tonight. I'm really sorry for the delay I've been away for days now. Thanks for your help I really appreciate.

Copy link
Member

Choose a reason for hiding this comment

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

@McZenith No worries, thanks for working on this! You can go ahead and implement the format that @devongovett suggested above.

LFDanLu
LFDanLu previously approved these changes Aug 31, 2020
@devongovett
Copy link
Member

Hey @McZenith! I've updated things a little after reconsidering the API for this to try to make it less confusing. We now have an isDisabled option rather than isOpen that is true by default (confusing). I've also added a test to ensure things are working. Hope you don't mind me pushing to your branch. Thanks again for the contribution!

@devongovett devongovett merged commit 1951be5 into adobe:main Sep 11, 2020
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.

usePreventScroll should be controllable
3 participants