Skip to content

Commit 2f60b27

Browse files
committed
Revert Sticky Header to use ScrollablePane
1 parent bea98ff commit 2f60b27

File tree

2 files changed

+83
-43
lines changed

2 files changed

+83
-43
lines changed

src/controls/listView/ListView.stickyHeader.module.scss

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/controls/listView/ListView.tsx

Lines changed: 83 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import * as React from 'react';
22
import styles from './ListView.DragDrop.module.scss';
3-
import stickyHeaderstyles from './ListView.stickyHeader.module.scss';
4-
import { DetailsList, DetailsListLayoutMode, Selection, SelectionMode, IGroup } from 'office-ui-fabric-react/lib/DetailsList';
3+
import { ScrollablePane, ScrollbarVisibility } from 'office-ui-fabric-react/lib/ScrollablePane';
4+
import { Sticky, StickyPositionType } from 'office-ui-fabric-react/lib/Sticky';
5+
import { IRenderFunction } from 'office-ui-fabric-react/lib/Utilities';
6+
import { mergeStyleSets } from 'office-ui-fabric-react/lib/Styling';
7+
import { DetailsList, DetailsListLayoutMode, Selection, SelectionMode, IGroup, IDetailsHeaderProps } from 'office-ui-fabric-react/lib/DetailsList';
58
import { IListViewProps, IListViewState, IViewField, IGrouping, GroupOrder } from './IListView';
69
import { IColumn, IGroupRenderProps } from 'office-ui-fabric-react/lib/components/DetailsList';
710
import { findIndex, has, sortBy, isEqual, cloneDeep } from '@microsoft/sp-lodash-subset';
@@ -15,6 +18,35 @@ import filter from 'lodash/filter';
1518
import { SearchBox } from 'office-ui-fabric-react/lib/SearchBox';
1619
import { Guid } from '@microsoft/sp-core-library';
1720

21+
const classNames = mergeStyleSets({
22+
wrapper: {
23+
height: '50vh',
24+
position: 'relative'
25+
}
26+
});
27+
28+
/**
29+
* Wrap the listview in a scrollable pane if sticky header = true
30+
*/
31+
const ListViewWrapper = ({ stickyHeader, children }) => (stickyHeader ?
32+
<div className={classNames.wrapper} >
33+
<ScrollablePane scrollbarVisibility={ScrollbarVisibility.auto}>
34+
{children}
35+
</ScrollablePane>
36+
</div>
37+
: children
38+
);
39+
40+
/**
41+
* Lock the searchbox when scrolling if sticky header = true
42+
*/
43+
const SearchBoxWrapper = ({ stickyHeader, children }) => (stickyHeader ?
44+
<Sticky stickyPosition={StickyPositionType.Header}>
45+
{children}
46+
</Sticky>
47+
: children
48+
);
49+
1850

1951
/**
2052
* File type icon component
@@ -564,6 +596,23 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
564596
this.dragCounter = 0;
565597
}
566598
}
599+
/**
600+
* Custom render of header
601+
* @param props
602+
* @param defaultRender
603+
*/
604+
private _onRenderDetailsHeader: IRenderFunction<IDetailsHeaderProps> = (props, defaultRender) => {
605+
if (!props) {
606+
return null;
607+
}
608+
return (
609+
<Sticky stickyPosition={StickyPositionType.Header} isScrollSynced>
610+
{defaultRender!({
611+
...props,
612+
})}
613+
</Sticky>
614+
);
615+
}
567616
/**
568617
* Default React component render method
569618
*/
@@ -585,38 +634,39 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
585634
}
586635

587636
return (
588-
<div className={styles.DragDropArea}
589-
ref={this.dropRef}>
590-
{(dragStatus && dragDropFiles) &&
591-
<div className={styles.DragDropAreaBorder}>
592-
<div className={styles.DragDropAreaZone}>
593-
<Icon iconName="Download" className="ms-IconExample" />
594-
<div>{strings.UploadFileHeader}</div>
637+
<ListViewWrapper stickyHeader={!!this.props.stickyHeader}>
638+
<div className={styles.DragDropArea}
639+
ref={this.dropRef}>
640+
{(dragStatus && dragDropFiles) &&
641+
<div className={styles.DragDropAreaBorder}>
642+
<div className={styles.DragDropAreaZone}>
643+
<Icon iconName="Download" className="ms-IconExample" />
644+
<div>{strings.UploadFileHeader}</div>
645+
</div>
595646
</div>
596-
</div>
597-
}
598-
{
599-
showFilter &&
600-
<SearchBox placeholder={filterPlaceHolder || strings.ListViewFilterLabel} onSearch={this._updateFilterValue} onChange={this._updateFilterValue} value={filterValue} />
601-
}
602-
<DetailsList
603-
key="ListViewControl"
604-
items={items}
605-
columns={columns}
606-
groups={groups}
607-
selectionMode={selectionMode || SelectionMode.none}
608-
selectionPreservedOnEmptyClick={true}
609-
selection={this._selection}
610-
layoutMode={DetailsListLayoutMode.justified}
611-
compact={compact}
612-
setKey="ListViewControl"
613-
groupProps={groupProps}
614-
className={
615-
stickyHeader &&
616-
stickyHeaderstyles.StickyHeader
617-
}
618-
/>
619-
</div>
647+
}
648+
{
649+
showFilter &&
650+
<SearchBoxWrapper stickyHeader={!!this.props.stickyHeader}>
651+
<SearchBox placeholder={filterPlaceHolder || strings.ListViewFilterLabel} onSearch={this._updateFilterValue} onChange={this._updateFilterValue} value={filterValue} />
652+
</SearchBoxWrapper>
653+
}
654+
<DetailsList
655+
key="ListViewControl"
656+
items={items}
657+
columns={columns}
658+
groups={groups}
659+
selectionMode={selectionMode || SelectionMode.none}
660+
selectionPreservedOnEmptyClick={true}
661+
selection={this._selection}
662+
layoutMode={DetailsListLayoutMode.justified}
663+
compact={compact}
664+
setKey="ListViewControl"
665+
groupProps={groupProps}
666+
onRenderDetailsHeader={this._onRenderDetailsHeader}
667+
/>
668+
</div>
669+
</ListViewWrapper>
620670
);
621671
}
622672
}

0 commit comments

Comments
 (0)