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

Disable header row marker on single selection #935

Merged
merged 5 commits into from
May 10, 2024
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
5 changes: 4 additions & 1 deletion packages/core/src/data-editor/data-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
const rowMarkerTheme = rowMarkersObj?.theme ?? p.rowMarkerTheme;
const headerRowMarkerTheme = rowMarkersObj?.headerTheme;
const headerRowMarkerAlwaysVisible = rowMarkersObj?.headerAlwaysVisible;
const headerRowMarkerDisabled = rowSelect !== "multi";
const rowMarkerCheckboxStyle = rowMarkersObj?.checkboxStyle ?? "square";

const minColumnWidth = Math.max(minColumnWidthIn, 20);
Expand Down Expand Up @@ -1112,6 +1113,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
rowMarkerChecked,
headerRowMarkerTheme,
headerRowMarkerAlwaysVisible,
headerRowMarkerDisabled,
},
...columns,
];
Expand All @@ -1124,6 +1126,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
rowMarkerChecked,
headerRowMarkerTheme,
headerRowMarkerAlwaysVisible,
headerRowMarkerDisabled,
]);

const visibleRegionRef = React.useRef<VisibleRegion>({
Expand Down Expand Up @@ -1795,7 +1798,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
} else {
setSelectedRows(CompactSelection.fromSingleSelection(newSlice), undefined, isMultiRow);
}
} else if (isMultiRow || args.isTouch || rowSelectionMode === "multi") {
} else if (rowSelect === "multi" && (isMultiRow || args.isTouch || rowSelectionMode === "multi")) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An additional check for rowSelect == multi here to make sure that multi-selection is only allowed if it is actually configured.

if (isSelected) {
setSelectedRows(selectedRows.remove(row), undefined, true);
} else {
Expand Down
84 changes: 84 additions & 0 deletions packages/core/src/docs/examples/row-selections.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from "react";
import { DataEditorAll as DataEditor } from "../../data-editor-all.js";
import { type RowMarkerOptions } from "../../data-editor/data-editor.js";
import {
BeautifulWrapper,
Description,
PropName,
useMockDataGenerator,
defaultProps,
} from "../../data-editor/stories/utils.js";
import { SimpleThemeWrapper } from "../../stories/story-utils.js";

export default {
title: "Glide-Data-Grid/DataEditor Demos",

decorators: [
(Story: React.ComponentType) => (
<SimpleThemeWrapper>
<BeautifulWrapper
title="Row selections"
description={
<Description>
You can enable row selections by setting <PropName>rowSelect</PropName> prop to{" "}
<PropName>multi</PropName> for multi-selection or <PropName>single</PropName> for
single-selection. The row marker behavior and appearance can be controlled via the{" "}
<PropName>rowMarkers</PropName> prop.
</Description>
}>
<Story />
</BeautifulWrapper>
</SimpleThemeWrapper>
),
],
};

interface RowSelectionsProps {
rowSelect: "none" | "single" | "multi";
rowSelectionMode: "auto" | "multi";
rowMarkersKind: RowMarkerOptions["kind"];
rowMarkersCheckboxStyle: RowMarkerOptions["checkboxStyle"];
}

export const RowSelections: React.FC<RowSelectionsProps> = p => {
const { cols, getCellContent } = useMockDataGenerator(30);

return (
<DataEditor
{...defaultProps}
rowSelect={p.rowSelect}
rowSelectionMode={p.rowSelectionMode}
getCellContent={getCellContent}
rowMarkers={{
kind: p.rowMarkersKind,
checkboxStyle: p.rowMarkersCheckboxStyle,
}}
columns={cols}
rows={400}
/>
);
};
(RowSelections as any).args = {
rowSelect: "single",
rowSelectionMode: "auto",
rowMarkersKind: "checkbox-visible",
rowMarkersCheckboxStyle: "circle",
};
(RowSelections as any).argTypes = {
rowSelect: {
control: { type: "select" },
options: ["none", "single", "multi"],
},
rowSelectionMode: {
control: { type: "select" },
options: ["auto", "multi"],
},
rowMarkersKind: {
control: { type: "select" },
options: ["both", "checkbox", "number", "none", "clickable-number", "checkbox-visible"],
},
rowMarkersCheckboxStyle: {
control: { type: "select" },
options: ["square", "circle"],
},
};
1 change: 1 addition & 0 deletions packages/core/src/internal/data-grid/data-grid-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export type InnerColumnExtension = {
rowMarkerChecked?: BooleanIndeterminate | boolean;
headerRowMarkerTheme?: Partial<Theme>;
headerRowMarkerAlwaysVisible?: boolean;
headerRowMarkerDisabled?: boolean;
};

/** @category Columns */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function useMappedColumns(
rowMarkerChecked: c.rowMarkerChecked,
headerRowMarkerTheme: c.headerRowMarkerTheme,
headerRowMarkerAlwaysVisible: c.headerRowMarkerAlwaysVisible,
headerRowMarkerDisabled: c.headerRowMarkerDisabled,
})
),
[columns, freezeColumns]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ function drawHeaderInner(
isRtl: boolean,
headerLayout: HeaderLayout
) {
if (c.rowMarker !== undefined) {
if (c.rowMarker !== undefined && c.headerRowMarkerDisabled !== true) {
const checked = c.rowMarkerChecked;
if (checked !== true && c.headerRowMarkerAlwaysVisible !== true) {
ctx.globalAlpha = hoverAmount;
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/data-grid-lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function makeCol(title: string, sourceIndex: number, sticky: boolean, width: num
grow: undefined,
headerRowMarkerAlwaysVisible: undefined,
headerRowMarkerTheme: undefined,
headerRowMarkerDisabled: undefined,
hasMenu: undefined,
icon: undefined,
id: undefined,
Expand Down
Loading