-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix props validation for Breadcrumb #4666
Conversation
b450575
to
61224e6
Compare
@@ -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) { |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.)
There was a problem hiding this 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
61224e6
to
45c7a49
Compare
if (overflowIndex! < 0 || overflowIndex! > items.length - 1) { | ||
const { maxDisplayedItems, overflowIndex, items } = props; | ||
if (overflowIndex! < 0 || | ||
maxDisplayedItems! > 1 && overflowIndex! > maxDisplayedItems! - 1 || |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
* 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) ...
* 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) ...
Overview
This change is to address bug #4663:
items
is[]
).items.length
is0
, and also added validation againstmaxDisplayedItems
, since that impacts overflow behavior, too.