-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
feat(Search): prop to return the active result #1825
Conversation
src/modules/Search/Search.js
Outdated
* @param {SyntheticEvent} event - React's original SyntheticEvent. | ||
* @param {object} data - All props. | ||
*/ | ||
onActiveSelectionChange: PropTypes.func, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that onActiveSelectionChange
can be renamed to onSelectionChange
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@treyhuffine thanks for PR.
I left some feedback, it will awesome if we will also add new test for the prososed callback.
src/modules/Search/Search.js
Outdated
debug('handleActiveSelectionChange()') | ||
const { onActiveSelectionChange } = this.props | ||
const result = this.getSelectedResult() | ||
if (onActiveSelectionChange) onActiveSelectionChange(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can exclude there if-condition if we will use lodash's invoke
. Also, our callbacks should return props
as the second argument.
_.invoke(this.props, `onActiveSelectionChange`, e, { ...this.props, result})
@layershifter thanks, I'll fix and resubmit. |
@treyhuffine Thanks 👍 You can simply push your commits into the current branch instead of the new PR |
…React into feat/search-callback
Codecov Report
@@ Coverage Diff @@
## master #1825 +/- ##
=========================================
Coverage ? 99.75%
=========================================
Files ? 145
Lines ? 2478
Branches ? 0
=========================================
Hits ? 2472
Misses ? 6
Partials ? 0
Continue to review full report at Codecov.
|
@@ -301,11 +316,11 @@ export default class Search extends Component { | |||
switch (keyboardKey.getCode(e)) { | |||
case keyboardKey.ArrowDown: | |||
e.preventDefault() | |||
this.moveSelectionBy(1) | |||
this.moveSelectionBy(e, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need e
in handleSelectionChange
.
@@ -105,7 +105,7 @@ export interface SearchProps { | |||
* @param {SyntheticEvent} event - React's original SyntheticEvent. | |||
* @param {object} data - All props. | |||
*/ | |||
onResultSelect?: (event: React.MouseEvent<HTMLDivElement>, data: SearchProps) => void; | |||
onResultSelect?: (event: React.MouseEvent<HTMLDivElement>, data: SearchResultData) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data
there also contains result
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levithomason we're for review there.
Released in |
Return the active value in
<Search>
when navigating using the arrow keys