Files
powerpoint-toolbox/node_modules/@fluentui/react-menu/lib/components/MenuItemLink/useMenuItemLink.js
T
2025-03-07 19:22:02 +01:00

38 lines
1.3 KiB
JavaScript

import * as React from 'react';
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
import { useMenuItem_unstable } from '../MenuItem/useMenuItem';
/**
* Create the state required to render MenuItemLink.
*
* The returned state can be modified with hooks such as useMenuItemLinkStyles_unstable,
* before being passed to renderMenuItemLink_unstable.
*
* @param props - props from this instance of MenuItemLink
* @param ref - reference to root HTMLElement of MenuItemLink
*/ export const useMenuItemLink_unstable = (props, ref)=>{
// casting because the root slot changes from div to a
const baseState = useMenuItem_unstable(props, null);
// FIXME: casting because the root slot changes from div to a,
// ideal solution would be to extract common logic from useMenuItem_unstable root
// and use it in both without assuming element type
const _props = {
...props,
...baseState.root,
ref,
tabIndex: props.tabIndex
};
return {
...baseState,
components: {
...baseState.components,
root: 'a'
},
root: slot.always(getIntrinsicElementProps('a', {
role: 'menuitem',
..._props
}), {
elementType: 'a'
})
};
};