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

fix: column opacity issue when row selection is enabled #247

Open
wants to merge 1 commit into
base: v1
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ yarn-error.log*

# turbo
.turbo

#Intellij-based IDEs
.idea
32 changes: 31 additions & 1 deletion packages/mantine-react-table/src/body/MRT_TableBodyCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import {
type MouseEvent,
type RefObject,
} from 'react';
import { Box, Skeleton, useMantineTheme } from '@mantine/core';
import {
Box,
Skeleton,
useMantineTheme,
type MantineColor,
type Sx,
} from '@mantine/core';
import { MRT_EditCellTextInput } from '../inputs/MRT_EditCellTextInput';
import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
import { MRT_TableBodyCellValue } from './MRT_TableBodyCellValue';
Expand All @@ -34,6 +40,24 @@ interface Props<TData extends Record<string, any> = {}> {
virtualCell?: MRT_VirtualItem;
}

const getPinnedStyles = (backgroundColor: MantineColor): Sx => ({
'&[data-pinned="true"]': {
zIndex: 1,
position: 'sticky',
backgroundColor,
opacity: 0.98,
'&:before': {
content: '""',
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
backgroundColor: 'transparent',
},
}
});

export const MRT_TableBodyCell = <TData extends Record<string, any> = {}>({
cell,
isStriped,
Expand Down Expand Up @@ -203,6 +227,9 @@ export const MRT_TableBodyCell = <TData extends Record<string, any> = {}>({
}
}}
{...tableCellProps}
data-pinned={
column.getIsPinned() && column.columnDef.columnDefType !== 'group'
}
onDragEnter={handleDragEnter}
onDoubleClick={handleDoubleClick}
sx={(theme) => ({
Expand Down Expand Up @@ -238,6 +265,9 @@ export const MRT_TableBodyCell = <TData extends Record<string, any> = {}>({
theme,
tableCellProps,
}),
...getPinnedStyles(
theme.colorScheme === 'light' ? theme.white : theme.black,
),
...draggingBorders,
})}
>
Expand Down
56 changes: 47 additions & 9 deletions packages/mantine-react-table/src/body/MRT_TableBodyRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,54 @@ export const MRT_TableBodyRow = <TData extends Record<string, any> = {}>({
top: virtualRow ? 0 : undefined,
transition: virtualRow ? 'none' : 'all 100ms ease-in-out',
width: '100%',
'&:hover td': {
backgroundColor:
enableHover !== false
? row.getIsSelected()
? theme.fn.rgba(getPrimaryColor(theme), 0.2)
: theme.colorScheme === 'dark'
...(row.getIsSelected() && {
backgroundColor: theme.fn.rgba(getPrimaryColor(theme), 0.2),
td: {
'* > .mantine-Checkbox-root': {
zIndex: 0,
position: 'relative'
},
'&[data-pinned="true"]': {
backgroundColor:
theme.colorScheme === 'light' ? theme.white : theme.black,
'&:before': {
backgroundColor: theme.fn.rgba(getPrimaryColor(theme), 0.2),
},
},
},
}),
...(enableHover && {
'&:hover td': {
backgroundColor:
theme.colorScheme === 'dark'
? `${theme.fn.lighten(theme.colors.dark[7], 0.12)}`
: `${theme.fn.darken(theme.white, 0.05)}`
: undefined,
},
: `${theme.fn.darken(theme.white, 0.05)}`,
'&[data-pinned="true"]': {
backgroundColor:
theme.colorScheme === 'light'
? theme.white
: theme.colors.dark[7],
'&:before': {
backgroundColor:
theme.colorScheme === 'dark'
? `${theme.fn.lighten(theme.colors.dark[7], 0.12)}`
: `${theme.fn.darken(theme.white, 0.05)}`,
},
},
},
}),
...(row.getIsSelected() && {
'&:hover td': {
backgroundColor: theme.fn.rgba(getPrimaryColor(theme), 0.2),
'&[data-pinned="true"]': {
backgroundColor:
theme.colorScheme === 'light' ? theme.white : theme.black,
'&:before': {
backgroundColor: theme.fn.rgba(getPrimaryColor(theme), 0.2),
},
},
},
}),
...(tableRowProps?.sx instanceof Function
? tableRowProps.sx(theme)
: (tableRowProps?.sx as any)),
Expand Down
Loading