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

Allow stepper to be used as a controlled component #688

Merged
merged 2 commits into from
Jun 10, 2017

Conversation

mking-clari
Copy link
Contributor

@mking-clari mking-clari commented May 28, 2017

Implements #687

  • Provides the ability to use ArrowKeyStepper as a controlled component
  • My specific use case is the ability to select cells via click. Generally this allows the user to provide a single source of truth for all selection methods (include the ArrowKeyStepper's state).
  • When using ArrowKeyStepper as a controlled component:
    • Provide onScrollToChange({ scrollToColumn, scrollToRow }) as a prop
    • Provide scrollToColumn as a prop
    • Provide scrollToRow as a prop
    • If ArrowKeyStepper is being used as a controlled component, it does not call setState for performance reasons (instead it uses the props directly).

PR checklist

  • Tests are passing
  • Lint is passing
  • I added two new test cases:
    • Check that onScrollToChange is called when key down occurs
    • Check that onScrollToChange is not called when props are updated (if the change occurs via props, the source of truth already knows about the change)
  • I added an additional demo setting, Enable click selection. I have enabled this setting by default in the demo because I think users normally want to be able to click to select.

Let me know your feedback. I will be happy to make changes.

@mking-clari mking-clari force-pushed the stepper-controlled-component branch from 18fce36 to c7b5530 Compare May 28, 2017 20:41
Copy link
Owner

@bvaughn bvaughn 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 this work! Added some thoughts.

@@ -92,6 +97,10 @@ export default class ArrowKeyStepper extends PureComponent {
)
}

_isComponentState () {
Copy link
Owner

Choose a reason for hiding this comment

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

nit: Maybe useComponentState ?

return this._isComponentState() ? this.state : this.props
}

_setRelevantState ({ scrollToColumn, scrollToRow }) {
Copy link
Owner

Choose a reason for hiding this comment

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

nit: Maybe updateScrollState ?

@@ -147,4 +156,16 @@ export default class ArrowKeyStepper extends PureComponent {
this._rowStartIndex = rowStartIndex
this._rowStopIndex = rowStopIndex
}

_getRelevantState () {
Copy link
Owner

Choose a reason for hiding this comment

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

nit: Maybe getScrollState ?

yarn.lock Outdated
version "1.3.1"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
dependencies:
js-tokens "^3.0.0"

loose-envify@^1.3.0:
Copy link
Owner

Choose a reason for hiding this comment

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

Probably fine, but can we drop the yarn.lock changes from this PR since it's not actually introducing any new deps?

@@ -14,11 +14,12 @@ export default class ArrowKeyStepper extends PureComponent {
};

static propTypes = {
children: PropTypes.func.isRequired,
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]).isRequired,
Copy link
Owner

Choose a reason for hiding this comment

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

This change seems wrong. If you pass a node, wouldn't things break now since the render function expect children to always be a function?

className: PropTypes.string,
columnCount: PropTypes.number.isRequired,
disabled: PropTypes.bool.isRequired,
mode: PropTypes.oneOf(['cells', 'edges']),
onScrollToChange: PropTypes.func,
Copy link
Owner

Choose a reason for hiding this comment

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

Seems like it's at least feasible that someone might want to observe scroll changes without being in controlled mode. I wonder if controlled mode should be a more explicit flag (eg a isControlled boolean prop or something)?

@mking-clari mking-clari force-pushed the stepper-controlled-component branch 3 times, most recently from c02da77 to af427c8 Compare June 4, 2017 10:41
@mking-clari mking-clari force-pushed the stepper-controlled-component branch from af427c8 to bc74522 Compare June 4, 2017 10:42
@mking-clari
Copy link
Contributor Author

mking-clari commented Jun 4, 2017

@bvaughn Thanks for your feedback. Updated per your review.

note: I removed _useComponentState in favor of using this.props.isControlled directly.

@bvaughn bvaughn merged commit bc74522 into bvaughn:master Jun 10, 2017
@bvaughn
Copy link
Owner

bvaughn commented Jun 10, 2017

I just published this feature to NPM as [email protected], tagged next. If you'd like to test it pre-release you can via:

npm install react-virtualized@next

Assuming no problems are reported with the RC, this feature will go out with 9.8.0 sometime this weekend. 😁

@bvaughn
Copy link
Owner

bvaughn commented Jun 13, 2017

Haven't heard anything negative about the RC so I just released 9.8.0

@BrianTomlinClari BrianTomlinClari deleted the stepper-controlled-component branch June 9, 2023 16:47
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