-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Updated pickers with input attribute compatibility. #33243
base: master
Are you sure you want to change the base?
Updated pickers with input attribute compatibility. #33243
Conversation
@gouttierre @msft-fluent-ui-bot @JustSlone @layershifter @khmakoto @micahgodbolt Can someone please help me merge this? |
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.
Thanks for doing this work! I did an initial pass and left comments on stuff I saw. Let me know if they make sense, and if you have any questions!
change/@fluentui-react-fd94592f-6c11-434f-a340-fce340db9a34.json
Outdated
Show resolved
Hide resolved
packages/react-examples/src/react/PeoplePicker/PeoplePicker.Normal.Example.tsx
Outdated
Show resolved
Hide resolved
packages/react-examples/src/react/PeoplePicker/PeoplePicker.Normal.Example.tsx
Outdated
Show resolved
Hide resolved
packages/react-examples/src/react/PeoplePicker/PeoplePicker.List.Example.tsx
Outdated
Show resolved
Hide resolved
packages/react-examples/src/react/PeoplePicker/PeoplePicker.List.Example.tsx
Outdated
Show resolved
Hide resolved
packages/react-examples/src/react/PeoplePicker/PeoplePicker.Normal.Example.tsx
Outdated
Show resolved
Hide resolved
packages/react-examples/src/react/PeoplePicker/PeoplePicker.List.Example.tsx
Outdated
Show resolved
Hide resolved
error: css('ms-BasePicker-error', ''), | ||
label: css('ms-BasePicker-label', ''), |
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.
If you're not passing anything else here, you can just do:
error: css('ms-BasePicker-error', ''), | |
label: css('ms-BasePicker-label', ''), | |
error: 'ms-BasePicker-error', | |
label: 'ms-BasePicker-label', |
text: css('ms-BasePicker-text', legacyStyles.pickerText, this.state.isFocused && legacyStyles.inputFocused), | ||
itemsWrapper: legacyStyles.pickerItems, | ||
input: css('ms-BasePicker-input', legacyStyles.pickerInput, inputProps && inputProps.className), | ||
screenReaderText: legacyStyles.screenReaderOnly, | ||
}; | ||
|
||
const comboLabel = this.props['aria-label'] || inputProps?.['aria-label']; | ||
const inputId = inputProps?.id ? inputProps.id : this._ariaMap.combobox; |
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.
nit:
const inputId = inputProps?.id ? inputProps.id : this._ariaMap.combobox; | |
const inputId = inputProps?.id ?? this._ariaMap.combobox; |
protected _getDescribedBy = (items: T[], hasError: boolean): string => { | ||
const describedBy = []; | ||
if (items.length > 0) { | ||
describedBy.push(this._ariaMap.selectedItems); | ||
} | ||
if (hasError) { | ||
describedBy.push(this._ariaMap.error); | ||
} | ||
return describedBy.join(' '); | ||
}; |
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.
nit: You could also achieve this, possibly even with better performance, by doing simple string concatenation instead of pushing into an array and joining.
@@ -269,6 +282,7 @@ export class BasePicker<T extends {}, P extends IBasePickerProps<T>> | |||
|
|||
const suggestionsVisible = !!this.state.suggestionsVisible; | |||
const suggestionsAvailable = suggestionsVisible ? this._ariaMap.suggestionList : undefined; | |||
const hasError = typeof (this.state.errorMessage || this.props.errorMessage) !== 'undefined'; |
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 it's probably better if you define this as you did below:
const hasError = typeof (this.state.errorMessage || this.props.errorMessage) !== 'undefined'; | |
const hasError = !!(this.state.errorMessage ?? this.props.errorMessage); |
} | ||
|
||
protected renderError(className?: string): JSX.Element | null { | ||
const errorMessage = this.props.errorMessage || this.state.errorMessage; |
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 these be the other way around?
const errorMessage = this.props.errorMessage || this.state.errorMessage; | |
const errorMessage = this.state.errorMessage ?? this.props.errorMessage; |
const { className, inputProps, disabled, selectionAriaLabel, selectionRole = 'list', theme, styles } = this.props; | ||
|
||
const suggestionsVisible = !!this.state.suggestionsVisible; | ||
|
||
const suggestionsAvailable: string | undefined = suggestionsVisible ? this._ariaMap.suggestionList : undefined; | ||
const hasError = !!(this.state.errorMessage || this.props.errorMessage); |
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.
const hasError = !!(this.state.errorMessage || this.props.errorMessage); | |
const hasError = !!(this.state.errorMessage ?? this.props.errorMessage); |
error: css('ms-BasePicker-error', ''), | ||
label: css('ms-BasePicker-label', ''), |
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.
Same thing as above, you don't need to use css
here if you are only passing one classname
error: css('ms-BasePicker-error', ''), | |
label: css('ms-BasePicker-label', ''), | |
error: 'ms-BasePicker-error', | |
label: 'ms-BasePicker-label', |
@@ -1137,9 +1236,11 @@ export class BasePickerListBelow<T extends {}, P extends IBasePickerProps<T>> ex | |||
}; | |||
|
|||
const comboLabel = this.props['aria-label'] || inputProps?.['aria-label']; | |||
const inputId = inputProps?.id ? inputProps.id : this._ariaMap.combobox; |
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.
nit:
const inputId = inputProps?.id ? inputProps.id : this._ariaMap.combobox; | |
const inputId = inputProps?.id ?? this._ariaMap.combobox; |
Previous Behavior
The Picker components that extend the
BasePicker
andBasePickerListBelow
are missing properties that most other FluentUI user input component support. The missing properties include label, required, errorMessage, and onGetErrorMessage.New Behavior
The pickers now support the following optional properties:
TextField
.TextField
.ComboBox
.TextField
.Related Issue(s)