-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[DataGrid] Allows to customize variant of value input in filter panel #4826
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
Conversation
These are the results for the performance tests:
|
@@ -476,6 +498,7 @@ const GridFilterForm = React.forwardRef<HTMLDivElement, GridFilterFormProps>( | |||
applyValue={applyFilterChanges} | |||
focusElementRef={valueRef} | |||
{...currentOperator.InputComponentProps} | |||
{...valueInputTextFieldProps} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, this could also be a breaking change. If the input component spreads the rest of the props to the root element, receiving an unexpected prop will cause a console error. What do you think of adding InputComponentProps
and spreading it here? In v6, we kill valueInputProps
and the FormControl
surrounding it.
Instead of
<GridFilterPanel
filterFormProps={{
valueInputProps: { variant: 'outlined' },
}}
/>
users will do
<GridFilterPanel
filterFormProps={{
InputComponentProps: { variant: 'outlined' },
}}
/>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍That was another option I had in mind
About the naming, what do you think of TextFieldProps
instead of InputComponentProps
to be more specific?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't know if the input component is a text field or not, it could be anything. The filter operator already has InputComponentProps
. I was considering this name for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But variant
is not part of the InputComponentProps
.
The InputComponent will be a FilledInput
, OutlinedInput
or Input
component depending on the variant
prop value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was to allow any prop in InputComponentProps
, not restricting to only those from the text field variants. It's the role of the current input component to use the variant
received.
As example, the input component of the operators of a singleSelect
column is not a TextField, but an Autocomplete. We need to forward the prop to the element that can use it.
diff --git a/packages/grid/x-data-grid/src/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx b/packages/grid/x-data-grid/src/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx
index e757992be..d3fa254ca 100644
--- a/packages/grid/x-data-grid/src/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx
+++ b/packages/grid/x-data-grid/src/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.tsx
@@ -24,7 +24,7 @@ const isOptionEqualToValue: GridFilterInputMultipleSingleSelectProps['isOptionEq
const filter = createFilterOptions<any>();
function GridFilterInputMultipleSingleSelect(props: GridFilterInputMultipleSingleSelectProps) {
- const { item, applyValue, type, apiRef, focusElementRef, ...other } = props;
+ const { item, applyValue, type, apiRef, focusElementRef, variant = 'standard', ...other } = props;
const id = useId();
const resolvedColumn = item.columnField ? apiRef.current.getColumn(item.columnField) : null;
@@ -118,7 +118,7 @@ function GridFilterInputMultipleSingleSelect(props: GridFilterInputMultipleSingl
}}
inputRef={focusElementRef}
type={'singleSelect'}
- variant="standard"
+ variant={variant}
/>
)}
{...other}
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
@@ -69,6 +69,10 @@ export default function CustomFilterPanelContent() { | |||
size: 'small', | |||
sx: { mt: 'auto' }, | |||
}, | |||
InputComponentProps: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can reflect FilterFormValueInput > currentOperator.InputComponent
hierarchy in here?
I would expect something like this:
filterFormProps: {
valueInputProps: {
// will be passed to `FilterFormValueInput`
// ...
InputComponentProps: {
// will be passed to `currentOperator.InputComponent`
}
}
}
Especially since InputComponentProps
are only passed to value input, not to other inputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
import { GridFilterItem } from '../../../models/gridFilterItem'; | ||
|
||
export interface GridFilterInputValueProps { | ||
export type GridFilterInputValueProps<T> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we type it better?
import type { GridApiCommon } from '../../../models/api/gridApiCommon';
import type { GridApiCommunity } from '../../../models/api/gridApiCommunity';
export type GridFilterInputValueProps<Api extends GridApiCommon = GridApiCommunity> = {
// ...
apiRef: React.MutableRefObject<Api>;
Maybe something like this?
The Api
is optional, so no need for GridFilterInputValueProps<any>
in other places
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I get it correctly:
Api
will includes all the properties ofGridApiCommon
- By default we set it to
GridApiCommunity
- It can be override by writing for example
GridFilterInputValueProps<GridApiPro>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
| 'multiple' | ||
| 'color' | ||
>, | ||
GridFilterInputValueProps<GridApiCommon> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is GridApiCommon
necessary here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
effectively it's not
@@ -220,6 +220,8 @@ const GridFilterForm = React.forwardRef<HTMLDivElement, GridFilterFormProps>( | |||
const isBaseSelectNative = baseSelectProps.native ?? true; | |||
const OptionComponent = isBaseSelectNative ? 'option' : MenuItem; | |||
|
|||
const { InputComponentProps, ...propagatedValueInputProps } = valueInputProps; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We never used "propagated", but "other" is already being used. Maybe prefix it.
const { InputComponentProps, ...propagatedValueInputProps } = valueInputProps; | |
const { InputComponentProps, ...valueInputPropsOther } = valueInputProps; |
Fix #4822
The idea for know is to pass customization props to the filter input
Special case for Autocomplet input for which TextFields are not the root component