Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
- `PositionedOverlay` now exposes an imperative `forceReLayout()` API for programmatically triggering a re-render of the component ([#4385](https://github.com/Shopify/polaris-react/pull/4385))
- `Popover` now exposes an imperative `forceUpdatePosition()` API for programmatically triggering a re-render of the underlying overlay component ([#4385](https://github.com/Shopify/polaris-react/pull/4385))
- `PositionedOverlay` now exposes an imperative `forceUpdatePosition()` API for programmatically triggering a re-render of the component ([#4385](https://github.com/Shopify/polaris-react/pull/4385))
- Added `wrapOverflow` prop to `AutocompleteProps` props to force text-breakword ([#4416](https://github.com/Shopify/polaris-react/pull/4416))

### Bug fixes

Expand All @@ -34,6 +35,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
- Properly support `selected` prop for `Navigation.Item` when `url` prop is not specified ([#4375](https://github.com/Shopify/polaris-react/pull/4375))
- Fixed an accessibility bug in `Icon` where `aria-label` was used incorrectly ([#4414](https://github.com/Shopify/polaris-react/pull/4414))
- Fixed a bug in `Option` where the label would cause scrollbars to appear instead of wrapping ([#4411](https://github.com/Shopify/polaris-react/pull/4411))
- Fixed a bug in `MappedOption` where the label will generate a scrollbar when the content is too long ([#4416](https://github.com/Shopify/polaris-react/pull/4416))

### Documentation

Expand Down
5 changes: 4 additions & 1 deletion src/components/Autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export interface AutocompleteProps {
/** Allow more than one option to be selected */
allowMultiple?: boolean;
/** An action to render above the list of options */
actionBefore?: ActionListItemDescriptor;
actionBefore?: ActionListItemDescriptor & {
/** Specifies that if the label is too long it will wrap instead of being hidden */
wrapOverflow?: boolean;
};
/** Display loading state */
loading?: boolean;
/** Indicates if more results will load dynamically */
Expand Down
95 changes: 95 additions & 0 deletions src/components/Autocomplete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,101 @@ function AutocompleteActionBeforeExample() {
}
```

### Autocomplete with wrapping action

Use to indicate there are no search results.

```jsx
function AutocompleteActionBeforeExample() {
const deselectedOptions = [
{value: 'rustic', label: 'Rustic'},
{value: 'antique', label: 'Antique'},
{value: 'vinyl', label: 'Vinyl'},
{value: 'vintage', label: 'Vintage'},
{value: 'refurbished', label: 'Refurbished'},
];
const [selectedOptions, setSelectedOptions] = useState([]);
const [inputValue, setInputValue] = useState('');
const [options, setOptions] = useState(deselectedOptions);
const [loading, setLoading] = useState(false);

const updateText = useCallback(
(value) => {
setInputValue(value);

if (!loading) {
setLoading(true);
}

setTimeout(() => {
if (value === '') {
setOptions(deselectedOptions);
setLoading(false);
return;
}
const filterRegex = new RegExp(value, 'i');
const resultOptions = options.filter((option) =>
option.label.match(filterRegex),
);
setOptions(resultOptions);
setLoading(false);
}, 300);
},
[deselectedOptions, loading, options],
);

const updateSelection = useCallback(
(selected) => {
const selectedText = selected.map((selectedItem) => {
const matchedOption = options.find((option) => {
return option.value.match(selectedItem);
});
return matchedOption && matchedOption.label;
});
setSelectedOptions(selected);
setInputValue(selectedText[0]);
},
[options],
);

const textField = (
<Autocomplete.TextField
onChange={updateText}
label="Tags"
value={inputValue}
prefix={<Icon source={SearchMinor} color="inkLighter" />}
placeholder="Search"
/>
);

return (
<div style={{height: '225px'}}>
<Autocomplete
actionBefore={{
accessibilityLabel: 'Action label',
badge: {
status: 'new',
content: 'New!',
},
content:
'Action with long name that will need to wrap on small display in order to have a nice display',
ellipsis: true,
helpText: 'Help text',
icon: CirclePlusMinor,
wrapOverflow: true,
}}
options={options}
selected={selectedOptions}
onSelect={updateSelection}
listTitle="Suggested tags"
loading={loading}
textField={textField}
/>
</div>
);
}
```

### Autocomplete with destructive action

Use to indicate there are no search results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ $item-vertical-padding: ($item-min-height - line-height(body)) / 2;
.Text {
@include layout-flex-fix;
flex: 1 1 auto;

.ContentWrap {
@include text-breakword;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {useI18n} from '../../../../utilities/i18n';

import styles from './MappedAction.scss';

interface MappedAction extends ActionListItemDescriptor {}
interface MappedAction extends ActionListItemDescriptor {
wrapOverflow?: boolean;
}

export function MappedAction({
active,
Expand All @@ -29,11 +31,14 @@ export function MappedAction({
destructive,
badge,
helpText,
wrapOverflow = false,
}: MappedAction) {
const i18n = useI18n();

let prefixMarkup: React.ReactNode | null = null;

const contentOverflowStyle = wrapOverflow ? styles.ContentWrap : undefined;

if (prefix) {
prefixMarkup = <div className={styles.Prefix}>{prefix}</div>;
} else if (icon) {
Expand Down Expand Up @@ -69,14 +74,8 @@ export function MappedAction({

const contentMarkup = (
<div className={styles.Text}>
{helpText ? (
<>
<div>{contentText}</div>
<TextStyle variation="subdued">{helpText}</TextStyle>
</>
) : (
contentText
)}
<div className={contentOverflowStyle}>{contentText}</div>
{helpText ? <TextStyle variation="subdued">{helpText}</TextStyle> : null}
</div>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
.Content {
display: flex;
flex: 1;

@include text-breakword;
}

.Media {
Expand Down