Adding onPendingValueChanged callback#4105
Conversation
| } else if (currentPendingValueValidIndexOnHover !== prevState.currentPendingValueValidIndexOnHover) { | ||
| onPendingValueSet(currentOptions[currentPendingValueValidIndexOnHover], currentPendingValueValidIndexOnHover, undefined); | ||
| } else if (currentPendingValueValidIndex !== prevState.currentPendingValueValidIndex) { | ||
| onPendingValueSet(currentOptions[currentPendingValueValidIndex], currentPendingValueValidIndex, undefined); |
There was a problem hiding this comment.
Consider pulling this into a function to keep componentDidUpdate from getting too messy
There was a problem hiding this comment.
The else if statements are practically the same, consider simplifying to set a local variable for the index, and if that exists then call the callback using that index
| * Callback issued when the user changes the pending value in ComboBox | ||
| * If now value is set, we send undefined parameters | ||
| */ | ||
| onPendingValueSet?: (option?: IComboBoxOption, index?: number, value?: string) => void; |
There was a problem hiding this comment.
Maybe onPendingValueChanged is better name
…c-react into ComboBox_Add_onPendingValueSet_Callback
| const { | ||
| isOpen, | ||
| focused, | ||
| currentOptions, |
There was a problem hiding this comment.
Removing this that I don't need it anymore
|
Checked with these test cases:
|
| onPreviewExecute(currentOptions[currentPendingIndex], currentPendingIndex); | ||
| this._isInPreview = true; | ||
| } | ||
| } |
There was a problem hiding this comment.
What about the case when a user enters a value that doesn't already exist as an option on the comboBox (when allowFreeform is true)?
There was a problem hiding this comment.
That case I'm not sure if it's handled in Excel, so I'm skipping it. In legacy ribbon only available menu items have live preview.
…c-react into ComboBox_Add_onPendingValueSet_Callback
…hub.com/manueldosal/office-ui-fabric-react into ComboBox_Add_onPendingValueSet_Callback
| currentPendingValueValidIndexOnHover | ||
| } = this.state; | ||
|
|
||
| if (onPreviewExecute && onRevertPreviewExecute) { |
There was a problem hiding this comment.
Consider pulling this if check to the top of the function negating it and returning if it's true so the whole function isn't nested inside of the check
| * Callback issued when the user changes the pending value index in ComboBox | ||
| * This includes hovering or keyboarding to a menu item | ||
| */ | ||
| onPreviewExecute?: (option?: IComboBoxOption, index?: number, value?: string) => void; |
There was a problem hiding this comment.
This name isn't very clear, I think onPendingValueChanged is more clear
| /** | ||
| * Callback issued when user leaves the menu item in the ComboBox menu | ||
| */ | ||
| onRevertPreviewExecute?: () => void; |
There was a problem hiding this comment.
Do we actually need a revert callback? There's either going to be a new pending value or it's there's no pending value. I think onPendingValueChanged could handle both cases
|
|
||
| private _isScrollIdle: boolean; | ||
|
|
||
| private _isInPreview: boolean; |
There was a problem hiding this comment.
What is _isInPreview? Is it true when there's a pending value?
There was a problem hiding this comment.
This is when the pending values is not undefined
| onPreviewExecute(currentPendingIndex ? currentOptions[currentPendingIndex] : undefined, currentPendingIndex, pendingValue); | ||
| this._isInPreview = true; | ||
| } | ||
| } |
There was a problem hiding this comment.
Can you add comments for all of these if checks? This seems overly complex and it could potentially be restructured to be more simple and straight forward.
jspurlin
left a comment
There was a problem hiding this comment.
Consider having one callback, it should simplify things
| if (this._indexWithinBounds(currentOptions, currentPendingValueValidIndexOnHover)) { | ||
| currentPendingIndex = currentPendingValueValidIndexOnHover; | ||
| } else { | ||
| sendUndefinedPendingValue = true; |
There was a problem hiding this comment.
Consider changing this to true by default and then setting it to false inside of the if statements. It would remove the need for an else statement
|
|
||
| // Notify the new pending value if any of currentPendingIndex or pendingValue was changed. | ||
| if (!this._hasPendingValue && (currentPendingIndex || pendingValue)) { | ||
| onPendingValueChanged(currentPendingIndex ? currentOptions[currentPendingIndex] : undefined, currentPendingIndex, pendingValue); |
There was a problem hiding this comment.
Does currentPendingIndex ? currentOptions[currentPendingIndex] : undefined work as expected if currentPendingIndex === 0?
|
Hi,
Why send undefined instead of value is not undefined ? |
Pull request checklist
$ npm run changeDescription of changes
ComboBox: adding onPendingValueSet callback prop to run when pending value is changed.
Focus areas to test
Tested that hovering and using arrows through menu items runs the callback.
Checked with these test cases: