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

#479 #477 #395 - Picker - bug fixes #491

Merged
merged 4 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
3 changes: 2 additions & 1 deletion packages/react-components/src/components/Picker/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const Picker: React.FC<IPickerProps> = ({
return onSelect(null);
}

const newSelectedItems = items.filter((item) =>
const newSelectedItems = options.filter((item) =>
newSelectedItemsKeys.includes(item.key)
);

Expand Down Expand Up @@ -208,6 +208,7 @@ export const Picker: React.FC<IPickerProps> = ({
<TriggerBody
isOpen={isListOpen}
isSearchDisabled={searchDisabled}
isDisabled={disabled}
placeholder={placeholder}
iconSize={tagIconSize}
items={selected}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ $base-class: 'picker-list';
cursor: pointer;
padding: 6px 11px;
height: 36px;
overflow: hidden;

&:hover {
background-color: var(--surface-basic-hover);
Expand Down Expand Up @@ -72,6 +71,13 @@ $base-class: 'picker-list';
font-weight: 600;
}

&__content {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

&__custom {
width: 100%;
height: auto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ describe('<PickerList> component', () => {
});

it('should mark selected list item as selected', () => {
const { getByText } = renderComponent({
const { getByTestId } = renderComponent({
...defaultProps,
isOpen: true,
selectedItemsKeys: ['three'],
});

expect(getByText('Option three')).toHaveAttribute('aria-selected', 'true');
expect(getByTestId('three')).toHaveAttribute('aria-selected', 'true');
});

it('should mark selected list item as disabled', () => {
const { getByText } = renderComponent({
const { getByTestId } = renderComponent({
...defaultProps,
isOpen: true,
items: [{ key: 'three', name: 'Option three', disabled: true }],
});

expect(getByText('Option three')).toHaveAttribute('aria-disabled', 'true');
expect(getByTestId('three')).toHaveAttribute('aria-disabled', 'true');
});

it('should display default empty state if no filter result', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export const PickerList: React.FC<IPickerListProps> = ({

return (
<li
data-testid={item.key}
ref={(element) => {
if (currentItemKey === item.key) {
element?.scrollIntoView({ block: 'nearest' });
Expand All @@ -240,7 +241,9 @@ export const PickerList: React.FC<IPickerListProps> = ({
})}
onClick={() => !item.disabled && handleOnClick(item)}
>
{getOptionContent(item)}
<div className={styles[`${itemClassName}__content`]}>
{getOptionContent(item)}
</div>
{isItemSelected(item.key) && <Icon kind="link" source={Check} />}
</li>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ $base-class: 'picker-trigger-body';
gap: 4px;
justify-content: flex-start;

&__item {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

&__input {
display: flex;
flex-grow: 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import cx from 'clsx';

import { IPickerListItem } from './PickerList';
import { Tag } from '../Tag';
Expand All @@ -12,6 +13,7 @@ const baseClass = 'picker-trigger-body';
export interface ITriggerBodyProps {
isOpen: boolean;
isSearchDisabled?: boolean;
isDisabled?: boolean;
placeholder: string;
items?: IPickerListItem[] | null;
type: PickerType;
Expand All @@ -23,6 +25,7 @@ export interface ITriggerBodyProps {
export const TriggerBody: React.FC<ITriggerBodyProps> = ({
isOpen,
isSearchDisabled,
isDisabled,
placeholder,
items,
type,
Expand All @@ -45,7 +48,7 @@ export const TriggerBody: React.FC<ITriggerBodyProps> = ({
);
}

return item.name;
return <div className={styles[`${baseClass}__item`]}>{item.name}</div>;
};

const handleOnChange = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -75,7 +78,7 @@ export const TriggerBody: React.FC<ITriggerBodyProps> = ({
key={item.name}
className={styles[`${baseClass}__tag`]}
iconSize={iconSize}
dismissible
dismissible={!isDisabled}
onRemove={() => onItemRemove(item)}
>
{getSingleItem(item)}
Expand Down