Skip to content

Commit

Permalink
[@mantine/core] Button: Added new shouldOverrideDefaultTargetId prop …
Browse files Browse the repository at this point in the history
…for popover target
  • Loading branch information
rommelmamedov committed Aug 9, 2023
1 parent b32eeb1 commit b8456b9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/mantine-core/src/Popover/PopoverTarget/PopoverTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ export interface PopoverTargetProps {

/** Popup accessible type, 'dialog' by default */
popupType?: string;

/** Determines whether component should override default id of target element, defaults to true */
shouldOverrideDefaultTargetId?: boolean;
}

const defaultProps: Partial<PopoverTargetProps> = {
refProp: 'ref',
popupType: 'dialog',
shouldOverrideDefaultTargetId: true,
};

export const PopoverTarget = forwardRef<HTMLElement, PopoverTargetProps>((props, ref) => {
const { children, refProp, popupType, ...others } = useComponentDefaultProps(
'PopoverTarget',
defaultProps,
props
);
const { children, refProp, popupType, shouldOverrideDefaultTargetId, ...others } =
useComponentDefaultProps('PopoverTarget', defaultProps, props);

if (!isElement(children)) {
throw new Error(POPOVER_ERRORS.children);
Expand All @@ -42,7 +43,7 @@ export const PopoverTarget = forwardRef<HTMLElement, PopoverTargetProps>((props,
'aria-haspopup': popupType,
'aria-expanded': ctx.opened,
'aria-controls': ctx.getDropdownId(),
id: ctx.getTargetId(),
id: shouldOverrideDefaultTargetId ? ctx.getTargetId() : children.props.id,
}
: {};

Expand Down

0 comments on commit b8456b9

Please sign in to comment.