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

[base-ui] Update props using Array to ReadonlyArray type #40754

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/mui-base/src/Unstable_Popup/Popup.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface PopupOwnProps {
*
* @see https://floating-ui.com/docs/computePosition#middleware
*/
middleware?: Array<PopupMiddleware | null | undefined | false>;
middleware?: ReadonlyArray<PopupMiddleware | null | undefined | false>;
/**
* Distance between a popup and the trigger element.
* This prop is ignored when custom `middleware` is provided.
Expand Down
18 changes: 16 additions & 2 deletions packages/mui-base/src/useSlider/useSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,32 @@ function focusThumb({
}

function areValuesEqual(
newValue: number | Array<number>,
newValue: number | ReadonlyArray<number>,
oldValue: number | Array<number>,
): boolean {
if (typeof newValue === 'number' && typeof oldValue === 'number') {
return newValue === oldValue;
}
if (typeof newValue === 'object' && typeof oldValue === 'object') {
if (Array.isArray(newValue) && Array.isArray(oldValue)) {
return areArraysEqual(newValue, oldValue);
}
return false;
}

function areArraysEqual(arr1: ReadonlyArray<number>, arr2: ReadonlyArray<number>): boolean {
RaghavenderSingh marked this conversation as resolved.
Show resolved Hide resolved
if (arr1.length !== arr2.length) {
return false;
}

for (let i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) {
return false;
}
}

return true;
}

const axisProps = {
horizontal: {
offset: (percent: number) => ({ left: `${percent}%` }),
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-base/src/useSlider/useSlider.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface UseSliderParameters {
/**
* The default value. Use when the component is not controlled.
*/
defaultValue?: number | number[];
defaultValue?: number | ReadonlyArray<number>;
/**
* If `true`, the component is disabled.
* @default false
Expand Down Expand Up @@ -99,7 +99,7 @@ export interface UseSliderParameters {
* The value of the slider.
* For ranged sliders, provide an array with two values.
*/
value?: number | number[];
value?: number | ReadonlyArray<number>;
}

export interface Mark {
Expand Down
Loading