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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(table): table-column align prop #2900

Open
wants to merge 1 commit into
base: canary
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/rich-sloths-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@nextui-org/table": patch
"@nextui-org/theme": patch
---

Fix #2886 TableColumn align prop fixed, style improved.
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct the spelling mistake in the changeset description.

- Fix #2886 TableColumn align prop fixed, style improved.
+ Fix #2886: TableColumn align prop fixed; style improved.

Committable suggestion

鈥硷笍 IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Fix #2886 TableColumn align prop fixed, style improved.
Fix #2886: TableColumn align prop fixed; style improved.

5 changes: 4 additions & 1 deletion packages/components/table/src/table-cell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {GridNode} from "@react-types/grid";
import type {TableColumnProps} from "./base";

import {Key, useMemo} from "react";
import {forwardRef, HTMLNextUIProps} from "@nextui-org/system";
Expand Down Expand Up @@ -49,6 +50,8 @@ const TableCell = forwardRef<"td", TableCellProps>((props, ref) => {
);
}, [node.rendered]);

const columnProps: TableColumnProps<unknown> = node.column?.props || {};

return (
<Component
ref={domRef}
Expand All @@ -62,7 +65,7 @@ const TableCell = forwardRef<"td", TableCellProps>((props, ref) => {
}),
otherProps,
)}
className={slots.td?.({class: tdStyles})}
className={slots.td?.({align: columnProps.align, class: tdStyles})}
>
{cell}
</Component>
Expand Down
4 changes: 2 additions & 2 deletions packages/components/table/src/table-column-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const TableColumnHeader = forwardRef<"th", TableColumnHeaderProps>((props, ref)

const {isFocusVisible, focusProps} = useFocusRing();
const {isHovered, hoverProps} = useHover({});
const {hideHeader, ...columnProps} = node.props;
const {hideHeader, align, ...columnProps} = node.props;

const allowsSorting = columnProps.allowsSorting;

Expand All @@ -57,7 +57,7 @@ const TableColumnHeader = forwardRef<"th", TableColumnHeaderProps>((props, ref)
allowsSorting ? hoverProps : {},
otherProps,
)}
className={slots.th?.({class: thStyles})}
className={slots.th?.({align, class: thStyles})}
>
{hideHeader ? <VisuallyHidden>{node.rendered}</VisuallyHidden> : node.rendered}
{allowsSorting && (
Expand Down
17 changes: 15 additions & 2 deletions packages/core/theme/src/components/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ const table = tv({
"group",
"px-3",
"h-10",
"text-left",
"rtl:text-right",
"align-middle",
"bg-default-100",
"whitespace-nowrap",
Expand Down Expand Up @@ -249,6 +247,20 @@ const table = tv({
table: "w-full",
},
},
align: {
start: {
th: "text-start",
td: "text-start",
},
center: {
th: "text-center",
td: "text-center",
},
end: {
th: "text-end",
td: "text-end",
},
},
},
defaultVariants: {
layout: "auto",
Expand All @@ -259,6 +271,7 @@ const table = tv({
hideHeader: false,
isStriped: false,
fullWidth: true,
align: "start",
},
});

Expand Down