Skip to content

Fix bug in combo box where _selectedElement ref wasn't being set conditionally#4350

Merged
jspurlin merged 3 commits intomicrosoft:masterfrom
kelseyyoung:keyou/fix-combobox-scrolling-to-end
Mar 23, 2018
Merged

Fix bug in combo box where _selectedElement ref wasn't being set conditionally#4350
jspurlin merged 3 commits intomicrosoft:masterfrom
kelseyyoung:keyou/fix-combobox-scrolling-to-end

Conversation

@kelseyyoung
Copy link
Copy Markdown
Contributor

@kelseyyoung kelseyyoung commented Mar 23, 2018

Pull request checklist

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

Description of changes

There was a large change refs recently, and during that change a conditional ref assignment was omitted. The _selectedElement ref in ComboBox was always being set instead of only being set to the actual selected element. This meant the ComboBox Callout always scrolled to the bottom. This fix puts back that conditional ref assignment

PR of the original ref change: #4303

Focus areas to test

Tested in Fabric demo

@jspurlin
Copy link
Copy Markdown
Contributor

Consider adding a unit test to help catch if the ref gets screwed up in the future

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 adding a unit test

@jspurlin
Copy link
Copy Markdown
Contributor

jspurlin commented Mar 23, 2018

@kelseyyoung did you find the merge that introduced this regression? If so, can you list it here for reference?

@kelseyyoung
Copy link
Copy Markdown
Contributor Author

kelseyyoung commented Mar 23, 2018

After discussion with @jspurlin it seems like there's no good way to test it reliably

ariaLabel= {item.text }
disabled={ item.disabled }
> { <span ref={ this._selectedElement }>
> { <span ref={ isSelected ? this._selectedElement : '' }>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since we're trying to move away from string refs perhaps pass a noop?

const noop = () => {};

...

> { <span ref={ isSelected ? this._selectedElement : noop }>

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.

What about undefined? TSLint won't pass with an empty function block

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.

Yeah, I think undefined would be fine, you may need to update the declaration to allow for undefined

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.

I think it's fine as is, ref is already an optional prop and passing undefined should just make it not set to anything. I'll push that in a minute

@jspurlin jspurlin merged commit b163a65 into microsoft:master Mar 23, 2018
@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.

3 participants