Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix props validation for Breadcrumb #4666

Merged
merged 4 commits into from
Apr 25, 2018

Conversation

ThomasMichon
Copy link
Member

@ThomasMichon ThomasMichon commented Apr 24, 2018

Overview

This change is to address bug #4663:

  • Added unit test for the empty-props case (items is []).
  • Updated the validation logic to handle the case where items.length is 0, and also added validation against maxDisplayedItems, since that impacts overflow behavior, too.

@ThomasMichon ThomasMichon requested a review from dzearing April 24, 2018 20:20
@ThomasMichon ThomasMichon force-pushed the breadcrumb-validation branch from b450575 to 61224e6 Compare April 24, 2018 21:03
@lambertwang-zz lambertwang-zz self-requested a review April 25, 2018 00:15
@@ -204,7 +204,7 @@ export class Breadcrumb extends BaseComponent<IBreadcrumbProps, any> {
*/
private _validateProps(props: IBreadcrumbProps): void {
const { items, overflowIndex } = props;
if (overflowIndex! < 0 || overflowIndex! > items.length - 1) {
if (overflowIndex! < 0 || overflowIndex! > items.length) {
Copy link
Member

@JasonGore JasonGore Apr 25, 2018

Choose a reason for hiding this comment

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

This fixes the issue when items is of 0 length. However, if items is of length N and overflowIndex is also N, I think this new change will now consider that a valid scenario when it isn't. I wonder if instead overflowIndex should only be compared against items.length when items.length is > 0 (leaving the original items.length - 1 change in.)

Copy link
Member

Choose a reason for hiding this comment

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

(I guess some expect error test cases would be useful here too.)

Copy link
Member

@JasonGore JasonGore left a comment

Choose a reason for hiding this comment

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

Requesting feedback regarding potential bug introduced in validate function

@ThomasMichon ThomasMichon force-pushed the breadcrumb-validation branch from 61224e6 to 45c7a49 Compare April 25, 2018 16:08
if (overflowIndex! < 0 || overflowIndex! > items.length - 1) {
const { maxDisplayedItems, overflowIndex, items } = props;
if (overflowIndex! < 0 ||
maxDisplayedItems! > 1 && overflowIndex! > maxDisplayedItems! - 1 ||
Copy link
Member

@JasonGore JasonGore Apr 25, 2018

Choose a reason for hiding this comment

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

Should overflowIndex be compared against maxDisplayedItems when maxDisplayedItems is 1?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is enough sanity checking for the moment. The component doesn't actually break if you specify values out-of-bounds.

@ThomasMichon ThomasMichon merged commit 5e99f2d into microsoft:master Apr 25, 2018
Markionium added a commit to Markionium/office-ui-fabric-react that referenced this pull request Apr 26, 2018
* master: (42 commits)
  Applying package updates.
  ProgressIndicator: Finish conversion to mergeStyles (microsoft#4595)
  Fix props validation for Breadcrumb (microsoft#4666)
  No unused vars part of ts (microsoft#4670)
  Picker/Autofill: fixes several minor bugs. (microsoft#4569)
  Fix Calendar component PREV/NEXT month, year, and "Go to today" handlers firing twice (microsoft#4662)
  Applying package updates.
  Merge styles order (microsoft#4664)
  Fabric component: revert class change and make it backwards compatible (microsoft#4671)
  Addressing Issue microsoft#3707 - OverflowSet: Add the ability to set aria-label (microsoft#4667)
  Fix input type for Tile ARIA label prop (microsoft#4668)
  Fix theme slots for DetailsList header colors (microsoft#4658)
  Applying package updates.
  Jolore/calendar updates (microsoft#4643)
  Remove wordWrap setting. (microsoft#4657)
  Pivot: convert to mergeStyles - part 1  (microsoft#4656)
  Use the `data-is-scrollable` attribute on the correct ScrollablePane div (microsoft#4602)
  Applying package updates.
  Remove unused iconClassName prop from Nav.types (microsoft#4634)
  Jest snapshots: classes in animations should autoexpand. (microsoft#4647)
  ...
Markionium added a commit to Markionium/office-ui-fabric-react that referenced this pull request Apr 26, 2018
* master: (34 commits)
  Applying package updates.
  ProgressIndicator: Finish conversion to mergeStyles (microsoft#4595)
  Fix props validation for Breadcrumb (microsoft#4666)
  No unused vars part of ts (microsoft#4670)
  Picker/Autofill: fixes several minor bugs. (microsoft#4569)
  Fix Calendar component PREV/NEXT month, year, and "Go to today" handlers firing twice (microsoft#4662)
  Applying package updates.
  Merge styles order (microsoft#4664)
  Fabric component: revert class change and make it backwards compatible (microsoft#4671)
  Addressing Issue microsoft#3707 - OverflowSet: Add the ability to set aria-label (microsoft#4667)
  Fix input type for Tile ARIA label prop (microsoft#4668)
  Fix theme slots for DetailsList header colors (microsoft#4658)
  Applying package updates.
  Jolore/calendar updates (microsoft#4643)
  Remove wordWrap setting. (microsoft#4657)
  Pivot: convert to mergeStyles - part 1  (microsoft#4656)
  Use the `data-is-scrollable` attribute on the correct ScrollablePane div (microsoft#4602)
  Applying package updates.
  Remove unused iconClassName prop from Nav.types (microsoft#4634)
  Jest snapshots: classes in animations should autoexpand. (microsoft#4647)
  ...
@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