Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "ComboBox adding onPendingValueSet callback prop to run when pending value is changed",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "madosal@microsoft.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,17 @@ export class ComboBox extends BaseComponent<IComboBoxProps, IComboBoxState> {
allowFreeform,
value,
onMenuOpen,
onMenuDismissed
onMenuDismissed,
onPendingValueSet
} = this.props;
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

selectedIndex,
currentPendingValueValidIndex
currentPendingValue,
currentPendingValueValidIndex,
currentPendingValueValidIndexOnHover
} = this.state;

// If we are newly open or are open and the pending valid index changed,
Expand Down Expand Up @@ -243,6 +247,16 @@ export class ComboBox extends BaseComponent<IComboBoxProps, IComboBoxState> {
if (!isOpen && prevState.isOpen && onMenuDismissed) {
onMenuDismissed();
}

if (onPendingValueSet) {
if (currentPendingValue !== prevState.currentPendingValue) {
onPendingValueSet(undefined, undefined, currentPendingValue);
} 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

}
}
}

public componentWillUnmount() {
Expand Down Expand Up @@ -347,7 +361,7 @@ export class ComboBox extends BaseComponent<IComboBoxProps, IComboBoxState> {
styles={ this._getCaretButtonStyles() }
role='presentation'
aria-hidden={ isButtonAriaHidden }
data-is-focusable={false}
data-is-focusable={ false }
tabIndex={ -1 }
onClick={ this._onComboBoxClick }
iconProps={ buttonIconProps }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export interface IComboBoxProps extends ISelectableDroppableTextProps<IComboBox>
*/
onChanged?: (option?: IComboBoxOption, index?: number, value?: string) => void;

/**
* 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


/**
* Function that gets invoked when the ComboBox menu is launched
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ export class ComboBoxBasicExample extends React.Component<{}, {
value?: string;
}> {
private _testOptions =
[{ key: 'Header', text: 'Theme Fonts', itemType: SelectableOptionMenuItemType.Header },
{ key: 'A', text: 'Arial Black' },
{ key: 'B', text: 'Times New Roman' },
{ key: 'C', text: 'Comic Sans MS' },
{ key: 'divider_2', text: '-', itemType: SelectableOptionMenuItemType.Divider },
{ key: 'Header1', text: 'Other Options', itemType: SelectableOptionMenuItemType.Header },
{ key: 'D', text: 'Option d' },
{ key: 'E', text: 'Option e' },
{ key: 'F', text: 'Option f' },
{ key: 'G', text: 'Option g' },
{ key: 'H', text: 'Option h' },
{ key: 'I', text: 'Option i' },
{ key: 'J', text: 'Option j', disabled: true },
];
[{ key: 'Header', text: 'Theme Fonts', itemType: SelectableOptionMenuItemType.Header },
{ key: 'A', text: 'Arial Black' },
{ key: 'B', text: 'Times New Roman' },
{ key: 'C', text: 'Comic Sans MS' },
{ key: 'divider_2', text: '-', itemType: SelectableOptionMenuItemType.Divider },
{ key: 'Header1', text: 'Other Options', itemType: SelectableOptionMenuItemType.Header },
{ key: 'D', text: 'Option d' },
{ key: 'E', text: 'Option e' },
{ key: 'F', text: 'Option f' },
{ key: 'G', text: 'Option g' },
{ key: 'H', text: 'Option h' },
{ key: 'I', text: 'Option i' },
{ key: 'J', text: 'Option j', disabled: true },
];

private _fontMapping: { [key: string]: string } = {
['Arial Black']: '"Arial Black", "Arial Black_MSFontService", sans-serif',
Expand Down Expand Up @@ -81,7 +81,8 @@ export class ComboBoxBasicExample extends React.Component<{}, {
onFocus={ () => console.log('onFocus called') }
onBlur={ () => console.log('onBlur called') }
onMenuOpen={ () => console.log('ComboBox menu opened') }
// tslint:enable:jsx-no-lambda
onPendingValueSet={ (option, pendingIndex, pendingValue) => console.log('Pending value was changed. Pending index: ' + pendingIndex + '. Pending value: ' + pendingValue) }
// tslint:enable:jsx-no-lambda
/>

<PrimaryButton
Expand Down