Skip to content

Commit

Permalink
Fix #5802: ShowClearButton consistency (#5806)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Jan 19, 2024
1 parent f40b5f8 commit 51f94d8
Showing 1 changed file with 33 additions and 30 deletions.
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

0 comments on commit 51f94d8

Please sign in to comment.