Skip to content

Commit

Permalink
[@mantine/core] Do not validate options by default in OptionsDropdown…
Browse files Browse the repository at this point in the history
…, MultiSelect and Select

Previously Mantine punished the common scenario of duplicate keys too heavily, resulting in component failures in duplicate options data. Now duplicate values are silently ignored as in React.
  • Loading branch information
ustun-ed committed Nov 27, 2024
1 parent c83f5b0 commit 27cb9d7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type ComboboxLikeStylesNames = Exclude<ComboboxStylesNames, 'header' | 'f
export interface ComboboxLikeProps {
/** Data used to generate options */
data?: ComboboxData;

validateOptions?: boolean;
/** Controlled dropdown opened state */
dropdownOpened?: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ComboboxItem, ComboboxLikeRenderOptionInput, ComboboxParsedItem } from
import { defaultOptionsFilter, FilterOptionsInput } from './default-options-filter';
import { isEmptyComboboxData } from './is-empty-combobox-data';
import { isOptionsGroup } from './is-options-group';
import { validateOptions } from './validate-options';
import { validateOptions as validateOptionsFn } from './validate-options';
import classes from '../Combobox.module.css';

export type OptionsFilter = (input: FilterOptionsInput) => ComboboxParsedItem[];
Expand Down Expand Up @@ -95,6 +95,7 @@ export interface OptionsDropdownProps {
hidden?: boolean;
hiddenWhenEmpty?: boolean;
filterOptions?: boolean;
validateOptions?: boolean;
withCheckIcon?: boolean;
value?: string | string[] | null;
checkIconPosition?: 'left' | 'right';
Expand All @@ -116,6 +117,7 @@ export function OptionsDropdown({
maxDropdownHeight,
withScrollArea = true,
filterOptions = true,
validateOptions = false,
withCheckIcon = false,
value,
checkIconPosition,
Expand All @@ -126,7 +128,9 @@ export function OptionsDropdown({
scrollAreaProps,
'aria-label': ariaLabel,
}: OptionsDropdownProps) {
validateOptions(data);
if (validateOptions) {
validateOptionsFn(data);
}

const shouldFilter = typeof search === 'string';
const filteredData = shouldFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export const MultiSelect = factory<MultiSelectFactory>((_props, ref) => {
required,
mod,
renderOption,
validateOptions,
onRemove,
onClear,
scrollAreaProps,
Expand Down Expand Up @@ -412,6 +413,7 @@ export const MultiSelect = factory<MultiSelectFactory>((_props, ref) => {
withScrollArea={withScrollArea}
maxDropdownHeight={maxDropdownHeight}
filterOptions={searchable}
validateOptions={validateOptions}
value={_value}
checkIconPosition={checkIconPosition}
withCheckIcon={withCheckIcon}
Expand Down
2 changes: 2 additions & 0 deletions packages/@mantine/core/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const Select = factory<SelectFactory>((_props, ref) => {
clearButtonProps,
hiddenInputProps,
renderOption,
validateOptions,
onClear,
autoComplete,
scrollAreaProps,
Expand Down Expand Up @@ -300,6 +301,7 @@ export const Select = factory<SelectFactory>((_props, ref) => {
withScrollArea={withScrollArea}
maxDropdownHeight={maxDropdownHeight}
filterOptions={searchable && selectedOption?.label !== search}
validateOptions={validateOptions}
value={_value}
checkIconPosition={checkIconPosition}
withCheckIcon={withCheckIcon}
Expand Down

0 comments on commit 27cb9d7

Please sign in to comment.