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 #5802: ShowClearButton consistency #5806

Merged
merged 1 commit into from
Jan 19, 2024
Merged
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
63 changes: 33 additions & 30 deletions components/lib/datatable/ColumnFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ export const ColumnFilter = React.memo((props) => {
return filterModel && filterModel.matchMode === matchMode;
};

const showMenuButton = () => {
return getColumnProp('showFilterMenu') && (props.display === 'row' ? getColumnProp('dataType') !== 'boolean' : true);
};

const matchModes = () => {
return (
getColumnProp('filterMatchModeOptions') ||
Expand All @@ -90,6 +86,14 @@ export const ColumnFilter = React.memo((props) => {
);
};

const isShowMenuButton = () => {
return getColumnProp('showFilterMenu') && (props.display === 'row' ? getColumnProp('dataType') !== 'boolean' : true);
};

const isShowClearButton = () => {
return getColumnProp('showClearButton') && props.display === 'row';
};

const isShowMatchModes = () => {
return getColumnProp('dataType') !== 'boolean' && getColumnProp('showFilterMatchModes') && matchModes() && getColumnProp('showFilterMenuOptions');
};
Expand Down Expand Up @@ -523,7 +527,7 @@ export const ColumnFilter = React.memo((props) => {
};

const createMenuButton = () => {
if (!showMenuButton()) {
if (!isShowMenuButton()) {
return null;
}

Expand Down Expand Up @@ -563,6 +567,10 @@ export const ColumnFilter = React.memo((props) => {
};

const createClearButton = () => {
if (!isShowClearButton()) {
return null;
}

const filterClearIconProps = mergeProps(
{
'aria-hidden': true
Expand All @@ -571,32 +579,27 @@ export const ColumnFilter = React.memo((props) => {
);
const icon = props.filterClearIcon || <FilterSlashIcon {...filterClearIconProps} />;
const filterClearIcon = IconUtils.getJSXIcon(icon, { ...filterClearIconProps }, { props });
const clearLabel = clearButtonLabel();
const headerFilterClearButtonProps = mergeProps(
{
className: cx('headerFilterClearButton', { hasRowFilter }),
type: 'button',
onClick: (e) => clearFilter(e),
'aria-label': clearLabel
},
getColumnPTOptions('headerFilterClearButton', {
context: {
hidden: hasRowFilter()
}
})
);

if (getColumnProp('showClearButton') && props.display === 'row') {
const clearLabel = clearButtonLabel();
const headerFilterClearButtonProps = mergeProps(
{
className: cx('headerFilterClearButton', { hasRowFilter }),
type: 'button',
onClick: (e) => clearFilter(e),
'aria-label': clearLabel
},
getColumnPTOptions('headerFilterClearButton', {
context: {
hidden: hasRowFilter()
}
})
);

return (
<button {...headerFilterClearButtonProps}>
{filterClearIcon}
<Ripple />
</button>
);
}

return null;
return (
<button {...headerFilterClearButtonProps}>
{filterClearIcon}
<Ripple />
</button>
);
};

const createRowItems = () => {
Expand Down
Loading