Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: add `unstable_hasDefault` option in `useArrowNavigationGroup` that specifies the arrow navigation group has default focusable item",
"packageName": "@fluentui/react-tabster",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface UseArrowNavigationGroupOptions {
ignoreDefaultKeydown?: Types.FocusableProps['ignoreKeydown'];
memorizeCurrent?: boolean;
tabbable?: boolean;
unstable_hasDefault?: boolean;
}

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,29 @@ export interface UseArrowNavigationGroupOptions {
* Tabster should ignore default handling of keydown events
*/
ignoreDefaultKeydown?: Types.FocusableProps['ignoreKeydown'];
/**
* The default focusable item in the group will be an element with Focusable.isDefault property.
* Note that there is no way in \@fluentui/react-tabster to set default focusable element,
* and this option is currently for internal testing purposes only.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
unstable_hasDefault?: boolean;
}

/**
* A hook that returns the necessary tabster attributes to support arrow key navigation
* @param options - Options to configure keyboard navigation
*/
export const useArrowNavigationGroup = (options: UseArrowNavigationGroupOptions = {}): Types.TabsterDOMAttribute => {
const { circular, axis, memorizeCurrent, tabbable, ignoreDefaultKeydown } = options;
const {
circular,
axis,
memorizeCurrent,
tabbable,
ignoreDefaultKeydown,
// eslint-disable-next-line @typescript-eslint/naming-convention
unstable_hasDefault,
} = options;
const tabster = useTabster();

if (tabster) {
Expand All @@ -43,8 +58,9 @@ export const useArrowNavigationGroup = (options: UseArrowNavigationGroupOptions
mover: {
cyclic: !!circular,
direction: axisToMoverDirection(axis ?? 'vertical'),
memorizeCurrent: memorizeCurrent,
tabbable: tabbable,
memorizeCurrent,
tabbable,
hasDefault: unstable_hasDefault,
},
...(ignoreDefaultKeydown && {
focusable: {
Expand Down