73 lines
2.5 KiB
JavaScript
73 lines
2.5 KiB
JavaScript
'use client';
|
|
import * as React from 'react';
|
|
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
|
|
import { useArrowNavigationGroup } from '@fluentui/react-tabster';
|
|
/**
|
|
* Create the state required to render Breadcrumb.
|
|
*
|
|
* The returned state can be modified with hooks such as useBreadcrumbStyles_unstable,
|
|
* before being passed to renderBreadcrumb_unstable.
|
|
*
|
|
* @param props - props from this instance of Breadcrumb
|
|
* @param ref - reference to root HTMLElement of Breadcrumb
|
|
*/ export const useBreadcrumb_unstable = (props, ref)=>{
|
|
const { focusMode = 'tab', size = 'medium', ...breadcrumbProps } = props;
|
|
const state = useBreadcrumbBase_unstable(breadcrumbProps, ref);
|
|
const focusAttributes = useBreadcrumbA11yBehavior_unstable({
|
|
focusMode
|
|
});
|
|
return {
|
|
...state,
|
|
root: {
|
|
...focusAttributes,
|
|
...state.root
|
|
},
|
|
size
|
|
};
|
|
};
|
|
/**
|
|
* Base hook for Breadcrumb component, which manages state related to slots structure and ARIA attributes.
|
|
*
|
|
* Note: keyboard navigation behavior is not handled in this hook, but in useBreadcrumbA11yBehavior_unstable.
|
|
*
|
|
* @param props - props from this instance of Breadcrumb
|
|
* @param ref - reference to root HTMLElement of Breadcrumb
|
|
*/ export const useBreadcrumbBase_unstable = (props, ref)=>{
|
|
const { focusMode = 'tab', list, ...rest } = props;
|
|
var _props_arialabel;
|
|
return {
|
|
components: {
|
|
root: 'nav',
|
|
list: 'ol'
|
|
},
|
|
root: slot.always(getIntrinsicElementProps('nav', {
|
|
ref,
|
|
'aria-label': (_props_arialabel = props['aria-label']) !== null && _props_arialabel !== void 0 ? _props_arialabel : 'breadcrumb',
|
|
...rest
|
|
}), {
|
|
elementType: 'nav'
|
|
}),
|
|
list: slot.optional(list, {
|
|
renderByDefault: true,
|
|
defaultProps: {
|
|
role: 'list'
|
|
},
|
|
elementType: 'ol'
|
|
})
|
|
};
|
|
};
|
|
/**
|
|
* Hook to get accessibility attributes for Breadcrumb component, such as roving tab index.
|
|
* Based on Tabster's useArrowNavigationGroup.
|
|
*
|
|
* @param focusMode - whether the Breadcrumb uses arrow key navigation or tab key navigation
|
|
* @returns Tabster DOM attributes
|
|
*/ export const useBreadcrumbA11yBehavior_unstable = ({ focusMode })=>{
|
|
const focusAttributes = useArrowNavigationGroup({
|
|
circular: true,
|
|
axis: 'horizontal',
|
|
memorizeCurrent: true
|
|
});
|
|
return focusMode === 'arrow' ? focusAttributes : {};
|
|
};
|