-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[TableSortLabel] sort icon still can be hidden when hideSortIcon={false} #38800
Comments
Hmm, it seems like it was designed to be this way, and this is more of a feature request - allow, trough some combination of props, to be able to see which columns can be sorted or not at a glance. |
I was able to achieve my desired behavior with this: import ImportExportIcon from "@mui/icons-material/ImportExport";
import TableSortLabel, { tableSortLabelClasses } from "@mui/material/TableSortLabel";
type MyTableSortLabelProps = {
columnId: number;
columnUnsortable?: boolean;
orderBy: number;
orderDir: "asc" | "desc";
onClickSort: (column: number) => void;
children: React.ReactNode;
};
export const MyTableSortLabel: React.FC<MyTableSortLabelProps> = ({
columnId,
columnUnsortable,
orderBy,
orderDir,
onClickSort,
children
}) => {
if (columnUnsortable) {
return <>{children}</>;
}
const active = orderBy === columnId;
return (
<TableSortLabel
active={active}
direction={active ? orderDir : "asc"}
onClick={() => onClickSort(columnId)}
sx={{
[`.${tableSortLabelClasses.icon}`]: {
opacity: 0.5
}
}}
IconComponent={active ? undefined : ImportExportIcon}
>
{children}
</TableSortLabel>
);
}; This still can be implemented, or we could just document this as a recipie in on the page. Or this issue can just be closed. |
The docs for
So as per the docs:
It's the intended behaviour. If you are not interacting with it,
For that the label should be active. See - https://codesandbox.io/s/relaxed-orla-wwlpcv?file=/src/App.tsx:1243-1291 |
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example:
https://codesandbox.io/s/cool-leftpad-c3lckl?file=/src/App.tsx
Steps:
hover and click the labels
Current behavior 😯
When
hideSortIcon
is false, arrow is still hidden on a label you're not interacting withExpected behavior 🤔
When
hideSortIcon
is false, arrow is shown in some way at all timesContext 🔦
Some of columns in my table are not sortable, and it is impossible to know if they are, unless you hover the column
Your environment 🌎
see sandbox
The text was updated successfully, but these errors were encountered: