Skip to content

Commit

Permalink
Merge pull request #5818 from matuzalemsteles/clay-new-feature
Browse files Browse the repository at this point in the history
feat(@clayui/core): add new API to omit a column to columns visibility
  • Loading branch information
matuzalemsteles authored May 16, 2024
2 parents be6beba + 2e8d0f6 commit 02e137d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/clay-core/src/table/Head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function HeadInner<T extends Record<string, any>>(
ref: React.Ref<HTMLTableSectionElement>
) {
const {
alwaysVisibleColumns,
columnsVisibility,
messages,
onHeadCellsChange,
Expand Down Expand Up @@ -97,7 +98,12 @@ function HeadInner<T extends Record<string, any>>(
'columnsVisibilityHeader'
]!,
},
...collection.getItems(),
...collection
.getItems()
.filter(
(item) =>
!alwaysVisibleColumns.has(item)
),
]}
style={{
maxWidth: '210px',
Expand Down
8 changes: 8 additions & 0 deletions packages/clay-core/src/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import {useTreeNavigation} from './useTreeNavigation';
import type {AnnouncerAPI} from '../live-announcer';

export type Props = {
/**
* Defines the columns that are always visible and will be ignored by the
* visible columns functionality.
*/
alwaysVisibleColumns?: Set<React.Key>;

/**
* Flag to enable column visibility control.
*/
Expand Down Expand Up @@ -109,6 +115,7 @@ const defaultSet = new Set<React.Key>();
export const Table = React.forwardRef<HTMLDivElement, Props>(
function TableInner(
{
alwaysVisibleColumns = new Set(),
columnsVisibility = true,
children,
className,
Expand Down Expand Up @@ -203,6 +210,7 @@ export const Table = React.forwardRef<HTMLDivElement, Props>(
>
<TableContext.Provider
value={{
alwaysVisibleColumns,
columnsVisibility,
expandedKeys,
headCellsCount,
Expand Down
1 change: 1 addition & 0 deletions packages/clay-core/src/table/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type Sorting = {
};

type Context = {
alwaysVisibleColumns: Set<React.Key>;
columnsVisibility: boolean;
expandedKeys: Set<React.Key>;
headCellsCount: number;
Expand Down

0 comments on commit 02e137d

Please sign in to comment.