Skip to content
Merged
9 changes: 8 additions & 1 deletion packages/@react-spectrum/list/src/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ interface ListViewProps<T> extends CollectionBase<T>, DOMProps, AriaLabelingProp
isQuiet?: boolean,
/** The current loading state of the ListView. Determines whether or not the progress circle should be shown. */
loadingState?: LoadingState,
/**
* Sets the text behavior for the row contents.
* @default 'truncate'
*/
overflowMode?: 'truncate' | 'wrap',
/** Sets what the ListView should render when there is no content to display. */
renderEmptyState?: () => JSX.Element,
/**
Expand All @@ -112,6 +117,7 @@ function ListView<T extends object>(props: ListViewProps<T>, ref: DOMRef<HTMLDiv
onLoadMore,
loadingState,
isQuiet,
overflowMode = 'truncate',
onAction,
dragHooks,
...otherProps
Expand Down Expand Up @@ -210,7 +216,8 @@ function ListView<T extends object>(props: ListViewProps<T>, ref: DOMRef<HTMLDiv
'react-spectrum-ListView--loadingMore': loadingState === 'loadingMore',
'react-spectrum-ListView--isScrollingVertically': isVerticalScrollbarVisible,
'react-spectrum-ListView--isScrollingHorizontally': isHorizontalScrollbarVisible,
'react-spectrum-ListView--hasAnyChildren': hasAnyChildren
'react-spectrum-ListView--hasAnyChildren': hasAnyChildren,
'react-spectrum-ListView--wrap': overflowMode === 'wrap'
},
styleProps.className
)
Expand Down
11 changes: 11 additions & 0 deletions packages/@react-spectrum/list/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@
}
}
}
&.react-spectrum-ListView--wrap .react-spectrum-ListViewItem {
& .react-spectrum-ListViewItem-content,
& .react-spectrum-ListViewItem-description {
white-space: normal;
}
}
}

.react-spectrum-ListView-row {
Expand Down Expand Up @@ -299,6 +305,11 @@
.react-spectrum-ListViewItem-content,
.react-spectrum-ListViewItem-description {
flex-grow: 1;

/* truncate text with ellipsis */
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}

.react-spectrum-ListViewItem-content {
Expand Down
34 changes: 32 additions & 2 deletions packages/@react-spectrum/list/stories/ListView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {IllustratedMessage} from '@react-spectrum/illustratedmessage';
import {Image} from '@react-spectrum/image';
import Info from '@spectrum-icons/workflow/Info';
import {Item, ListView} from '../';
import {Link} from '@react-spectrum/link';
import NoSearchResults from '@spectrum-icons/illustrations/src/NoSearchResults';
import React, {useEffect, useState} from 'react';
import {storiesOf} from '@storybook/react';
Expand Down Expand Up @@ -326,8 +327,37 @@ storiesOf('ListView', module)
<Droppable />
<DragExample listViewProps={{selectionStyle: 'highlight', onAction: action('onAction')}} dragHookOptions={{onDragStart: action('dragStart'), onDragEnd: action('dragEnd')}} />
</Flex>
), {description: {data: 'Folders are non-draggable.'}}
);
), {description: {data: 'Folders are non-draggable.'}})
.add('overflowMode="truncate" (default)', () => (
<ListView width="250px" overflowMode="truncate">
<Item textValue="row 1">row 1 with a very very very very very long title</Item>
<Item textValue="row 2">
<Text>Text slot with a really really really long name</Text>
<Text slot="description">Description slot with a really really long name</Text>
</Item>
<Item textValue="row 3">
<Content>Content slot with really really long name</Content>
</Item>
<Item textValue="row 4">
<Link >Link slot with a very very very very long name</Link>
</Item>
</ListView>
))
.add('overflowMode="wrap"', () => (
<ListView width="250px" overflowMode="wrap">
<Item textValue="row 1">row 1 with a very very very very very long title</Item>
<Item textValue="row 2">
<Text>Text slot with a really really really long name</Text>
<Text slot="description">Description slot with a really really long name</Text>
</Item>
<Item textValue="row 3">
<Content>Content slot with really really long name</Content>
</Item>
<Item textValue="row 4">
<Link >Link slot with a very very very very long name</Link>
</Item>
</ListView>
));

function Example(props?) {
return (
Expand Down