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

Updated pickers with input attribute compatibility. #33243

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

tpalacino
Copy link

Previous Behavior

The Picker components that extend the BasePicker and BasePickerListBelow 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:

Property Description
label When specified renders consistently with how a label is rendered for a TextField.
required When specified renders consistently with how the required attribute is rendered for a TextField.
errorMessage When specified renders consistently with how an error message is rendered for a ComboBox.
onGetErrorMessage When specified behaves consistently with how an error message function behaves for a TextField.

Related Issue(s)

@tpalacino tpalacino marked this pull request as ready for review November 16, 2024 13:49
@tpalacino tpalacino requested a review from a team as a code owner November 16, 2024 13:49
@tpalacino
Copy link
Author

@gouttierre @msft-fluent-ui-bot @JustSlone @layershifter @khmakoto @micahgodbolt Can someone please help me merge this?

@JustSlone JustSlone assigned tudorpopams and unassigned tudorpopams Nov 16, 2024
Copy link
Contributor

@smhigley smhigley left a 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!

packages/react/src/components/pickers/BasePicker.types.ts Outdated Show resolved Hide resolved
packages/react/src/components/pickers/BasePicker.tsx Outdated Show resolved Hide resolved
packages/react/src/components/pickers/BasePicker.tsx Outdated Show resolved Hide resolved
packages/react/src/components/pickers/BasePicker.tsx Outdated Show resolved Hide resolved
@tpalacino
Copy link
Author

@smhigley & @khmakoto Feedback has been resolved

Comment on lines +306 to +307
error: css('ms-BasePicker-error', ''),
label: css('ms-BasePicker-label', ''),
Copy link
Member

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:

Suggested change
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;
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
const inputId = inputProps?.id ? inputProps.id : this._ariaMap.combobox;
const inputId = inputProps?.id ?? this._ariaMap.combobox;

Comment on lines +378 to +387
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(' ');
};
Copy link
Member

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';
Copy link
Member

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:

Suggested change
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;
Copy link
Member

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?

Suggested change
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);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const hasError = !!(this.state.errorMessage || this.props.errorMessage);
const hasError = !!(this.state.errorMessage ?? this.props.errorMessage);

Comment on lines +1225 to +1226
error: css('ms-BasePicker-error', ''),
label: css('ms-BasePicker-label', ''),
Copy link
Member

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

Suggested change
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;
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
const inputId = inputProps?.id ? inputProps.id : this._ariaMap.combobox;
const inputId = inputProps?.id ?? this._ariaMap.combobox;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NormalPeoplePicker required attribute
4 participants