Skip to content

Commit

Permalink
Dropdown: onChange ev.target now always consistent (#8538)
Browse files Browse the repository at this point in the history
* Updating onChange of Dropdown to have a consistent target.

* change file.

* Update change file.
  • Loading branch information
dzearing authored and msft-github-bot committed Apr 1, 2019
1 parent 24dab28 commit ac9cc96
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "Dropdown: The `onChange` callback's event target should always be the dropdown element, which contains the id attribute passed in through props.",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ export class DropdownBase extends BaseComponent<IDropdownInternalProps, IDropdow
// for single-select, option passed in will always be selected.
// for multi-select, flip the checked value
const changedOpt = multiSelect ? { ...options[index], selected: !checked } : options[index];
onChange(event, changedOpt, index);

onChange({ ...event, target: this._dropDown.current as EventTarget }, changedOpt, index);
}

if (onChanged) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ describe('Dropdown', () => {
const onChangeSpy = jest.fn();

try {
ReactDOM.render(<Dropdown label="testgroup" defaultSelectedKey="1" onChange={onChangeSpy} options={DEFAULT_OPTIONS} />, container);
ReactDOM.render(
<Dropdown id="foo" label="testgroup" defaultSelectedKey="1" onChange={onChangeSpy} options={DEFAULT_OPTIONS} />,
container
);
dropdownRoot = container.querySelector('.ms-Dropdown') as HTMLElement;

ReactTestUtils.Simulate.click(dropdownRoot);
Expand All @@ -171,6 +174,7 @@ describe('Dropdown', () => {
ReactTestUtils.Simulate.click(secondItemElement);
} finally {
expect(onChangeSpy).toHaveBeenCalledWith(expect.anything(), DEFAULT_OPTIONS[2], 2);
expect(onChangeSpy.mock.calls[0][0].target.id).toEqual('foo');
}
});

Expand Down

0 comments on commit ac9cc96

Please sign in to comment.