Skip to content

Adding onPendingValueChanged callback#4105

Merged
jspurlin merged 17 commits intomicrosoft:masterfrom
manueldosal:ComboBox_Add_onPendingValueSet_Callback
Mar 7, 2018
Merged

Adding onPendingValueChanged callback#4105
jspurlin merged 17 commits intomicrosoft:masterfrom
manueldosal:ComboBox_Add_onPendingValueSet_Callback

Conversation

@manueldosal
Copy link
Copy Markdown
Contributor

@manueldosal manueldosal commented Feb 27, 2018

Pull request checklist

  • [] Addresses an existing issue: Fixes #0000
  • Include a change request file using $ npm run change

Description 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:

  1. Hover over menu items
  2. Arrowing over menu items
  3. Move mouse out of the menu.
  4. Hover over a menu item and start arrowing down.
  5. Arrow down to a menu item, then hover over a different menu item.
  6. Hover over a menu item M, arrow down to a menu item N, move mouse over M.
  7. Change the text in the input.
  8. Autocomplete on input.
  9. Click on a menu item.
  10. Enter in input when changed value.

} else if (currentPendingValueValidIndexOnHover !== prevState.currentPendingValueValidIndexOnHover) {
onPendingValueSet(currentOptions[currentPendingValueValidIndexOnHover], currentPendingValueValidIndexOnHover, undefined);
} else if (currentPendingValueValidIndex !== prevState.currentPendingValueValidIndex) {
onPendingValueSet(currentOptions[currentPendingValueValidIndex], currentPendingValueValidIndex, undefined);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider pulling this into a function to keep componentDidUpdate from getting too messy

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe onPendingValueChanged is better name

const {
isOpen,
focused,
currentOptions,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removing this that I don't need it anymore

@manueldosal
Copy link
Copy Markdown
Contributor Author

Checked with these test cases:

  1. Hover over menu items
  2. Arrowing over menu items
  3. Move mouse out of the menu.
  4. Hover over a menu item and start arrowing down.
  5. Arrow down to a menu item, then hover over a different menu item.
  6. Hover over a menu item M, arrow down to a menu item N, move mouse over M.
  7. Change the text in the input.
  8. Autocomplete on input.
  9. Click on a menu item.
  10. Enter in input when changed value.

@manueldosal manueldosal changed the title Adding onPendingValueSet callback Adding onPreviewExecute and onRevertPreviewExecute callback Feb 28, 2018
@manueldosal manueldosal changed the title Adding onPreviewExecute and onRevertPreviewExecute callback Adding onPreviewExecute and onRevertPreviewExecute callbacks Feb 28, 2018
onPreviewExecute(currentOptions[currentPendingIndex], currentPendingIndex);
this._isInPreview = true;
}
}
Copy link
Copy Markdown
Contributor

@jspurlin jspurlin Feb 28, 2018

Choose a reason for hiding this comment

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

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)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

currentPendingValueValidIndexOnHover
} = this.state;

if (onPreviewExecute && onRevertPreviewExecute) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is _isInPreview? Is it true when there's a pending value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is when the pending values is not undefined

onPreviewExecute(currentPendingIndex ? currentOptions[currentPendingIndex] : undefined, currentPendingIndex, pendingValue);
this._isInPreview = true;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

@jspurlin jspurlin left a comment

Choose a reason for hiding this comment

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

Consider having one callback, it should simplify things

if (this._indexWithinBounds(currentOptions, currentPendingValueValidIndexOnHover)) {
currentPendingIndex = currentPendingValueValidIndexOnHover;
} else {
sendUndefinedPendingValue = true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does currentPendingIndex ? currentOptions[currentPendingIndex] : undefined work as expected if currentPendingIndex === 0?

@manueldosal manueldosal changed the title Adding onPreviewExecute and onRevertPreviewExecute callbacks Adding onPendingValueChanged callback Mar 7, 2018
@jspurlin jspurlin merged commit 48ad19d into microsoft:master Mar 7, 2018
@nataaad
Copy link
Copy Markdown

nataaad commented Apr 20, 2018

Hi,
I don't understand this comment :

Notify when there is a new pending index/value. Also, if there is a pending value, it needs to send undefined.

Why send undefined instead of value is not undefined ?

@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants