Skip to content

Commit

Permalink
chore: selectId
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanVor committed May 22, 2024
1 parent d8a2340 commit 186ac34
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ export const Select = React.forwardRef<HTMLButtonElement, SelectProps>(function
};

const uniqId = useUniqId();
const controlId = id ?? uniqId;
const selectId = `select-${controlId}`;
const selectId = id ?? uniqId;
const popupId = `select-popup-${selectId}`;

const _renderList = () => {
Expand Down Expand Up @@ -343,7 +342,6 @@ export const Select = React.forwardRef<HTMLButtonElement, SelectProps>(function
renderControl={renderControl}
value={value}
popupId={popupId}
id={controlId}
selectId={selectId}
activeIndex={activeIndex}
hasCounter={multiple && hasCounter}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export const SelectControl = React.forwardRef<HTMLButtonElement, ControlProps>((
renderCounter,
hasCounter,
title,
id,
} = props;
const showOptionsText = Boolean(selectedOptionsContent);
const showPlaceholder = Boolean(placeholder && !showOptionsText);
Expand Down Expand Up @@ -165,7 +164,6 @@ export const SelectControl = React.forwardRef<HTMLButtonElement, ControlProps>((
popupId,
selectId,
activeIndex,
id,
},
{value},
);
Expand All @@ -175,7 +173,7 @@ export const SelectControl = React.forwardRef<HTMLButtonElement, ControlProps>((
<React.Fragment>
<div className={selectControlBlock(controlMods)} role="group">
<button
id={id}
id={selectId}
ref={ref}
role="combobox"
aria-controls={popupId}
Expand Down
1 change: 0 additions & 1 deletion src/components/Select/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export type SelectRenderControlProps = {
open: boolean;
popupId: string;
selectId: string;
id?: string;
activeIndex?: number;
};
export type SelectRenderControlOptions = {
Expand Down
12 changes: 7 additions & 5 deletions src/components/TreeSelect/TreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ export const TreeSelect = React.forwardRef(function TreeSelect<T>(
ref: React.Ref<HTMLButtonElement>,
) {
const mobile = useMobile();
const uniqId = useUniqId();
const treeSelectId = id ?? uniqId;

const controlWrapRef = React.useRef<HTMLDivElement>(null);
const controlRef = React.useRef<HTMLElement>(null);
Expand Down Expand Up @@ -175,6 +173,10 @@ export const TreeSelect = React.forwardRef(function TreeSelect<T>(

const handleClose = React.useCallback(() => toggleOpen(false), [toggleOpen]);

const uniqId = useUniqId();
const treeSelectId = id ?? uniqId;
const popupId = `tree-select-popup-${treeSelectId}`;

const controlProps: TreeSelectRenderControlProps = {
open,
toggleOpen,
Expand All @@ -197,8 +199,8 @@ export const TreeSelect = React.forwardRef(function TreeSelect<T>(
).join(', ')}
view="normal"
pin="round-round"
popupId={`tree-select-popup-${treeSelectId}`}
selectId={`tree-select-${treeSelectId}`}
popupId={popupId}
selectId={treeSelectId}
/>
);

Expand Down Expand Up @@ -231,7 +233,7 @@ export const TreeSelect = React.forwardRef(function TreeSelect<T>(
handleClose={handleClose}
disablePortal={popupDisablePortal}
mobile={mobile}
id={`tree-select-popup-${treeSelectId}`}
id={popupId}
>
{slotBeforeListBody}

Expand Down

0 comments on commit 186ac34

Please sign in to comment.