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

Improvements for Picker component #336

Merged
merged 4 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ PickerWithGroupedOptions.args = {

export const PickerWithDisabledSearch = StoryTemplate.bind({});
PickerWithDisabledSearch.args = {
disableSearch: true,
searchDisabled: true,
options: [
{ key: 'groupA', name: 'Group A title header', groupHeader: true },
{ key: 'one', name: 'Option one' },
Expand Down
6 changes: 3 additions & 3 deletions packages/react-components/src/components/Picker/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface IPickerProps {
placeholder?: string;
isRequired?: boolean;
noSearchResultText?: string;
disableSearch?: boolean;
searchDisabled?: boolean;
sgraczyk marked this conversation as resolved.
Show resolved Hide resolved
onSelect: (selectedItem: IPickerListItem | null) => void;
}

Expand All @@ -35,7 +35,7 @@ export const Picker: React.FC<IPickerProps> = ({
placeholder = 'Select option',
isRequired,
noSearchResultText = 'No results found',
disableSearch = false,
searchDisabled = false,
onSelect,
}) => {
const [isListOpen, setIsListOpen] = React.useState<boolean>(false);
Expand Down Expand Up @@ -125,7 +125,7 @@ export const Picker: React.FC<IPickerProps> = ({
)}
<div className={styles[`${baseClass}__container`]}>
<Trigger
disabledSearch={disableSearch}
isSearchDisabled={searchDisabled}
isError={!!error}
isOpen={isListOpen}
isDisabled={disabled}
Expand Down
12 changes: 6 additions & 6 deletions packages/react-components/src/components/Picker/Trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const baseClass = 'picker-trigger';
export type TriggerSize = 'compact' | 'medium' | 'large';

export interface ITriggerProps {
disabledSearch: boolean;
isSearchDisabled: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we have isSearchDisabled as this is an internal part of Picker component, where our naming convention perfectly fits, the consumer doesn't see it.

Copy link

Choose a reason for hiding this comment

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

Fine for now, we'll rethink this later

isDisabled?: boolean;
isError?: boolean;
isItemSelected: boolean;
Expand All @@ -28,7 +28,7 @@ export interface ITriggerProps {

export const Trigger: React.FC<ITriggerProps> = ({
children,
disabledSearch,
isSearchDisabled,
isDisabled,
isError,
isItemSelected,
Expand Down Expand Up @@ -57,16 +57,16 @@ export const Trigger: React.FC<ITriggerProps> = ({
}
};

if (!disabledSearch) {
if (!isSearchDisabled) {
document.addEventListener('keydown', onKeyDown);
}

return () => {
if (!disabledSearch) {
if (!isSearchDisabled) {
document.removeEventListener('keydown', onKeyDown);
}
};
}, []);
}, [isSearchDisabled]);

const handleTriggerClick = () => {
onClick();
Expand All @@ -88,7 +88,7 @@ export const Trigger: React.FC<ITriggerProps> = ({
onClick={handleTriggerClick}
tabIndex={0}
>
{isOpen && !disabledSearch ? (
{isOpen && !isSearchDisabled ? (
<input
className={styles[`${baseClass}__input`]}
placeholder="Select option"
Expand Down