Skip to content

Commit

Permalink
include asociated component id with the options passed to a tab menu
Browse files Browse the repository at this point in the history
  • Loading branch information
heswell committed Aug 29, 2023
1 parent f9ee72c commit 6faa7f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
14 changes: 8 additions & 6 deletions vuu-ui/packages/vuu-layout/src/stack/Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export const Stack = forwardRef(function Stack(
ref: ForwardedRef<HTMLDivElement>
) {
const id = useId(idProp);

const { allowCloseTab, allowRenameTab } = TabstripProps;

// TODO integrate with Tabstrip drag drop
Expand Down Expand Up @@ -93,6 +92,9 @@ export const Stack = forwardRef(function Stack(
);

const activeChild = () => {
//TODO need to inject an id if child does not have one, so we can
// establish the aria-controls relationship. In a Vuu layout, there
// will always be an id.
if (React.isValidElement(children)) {
return children;
}
Expand All @@ -104,14 +106,14 @@ export const Stack = forwardRef(function Stack(

const renderTabs = () =>
getChildElements(children).map((child, idx) => {
const rootId = `${id}-${idx}`;
const { closeable = allowCloseTab, id: childId } = child.props;
const { closeable = allowCloseTab, id: childId = `${id}-${idx}` } =
child.props;
return (
<Tab
ariaControls={`${rootId}-tab`}
ariaControls={childId}
data-icon={getTabIcon(child, idx)}
key={childId ?? idx}
id={rootId}
key={childId}
id={`${childId}-tab`}
index={idx}
label={getTabLabel(child, idx)}
closeable={closeable}
Expand Down
1 change: 1 addition & 0 deletions vuu-ui/packages/vuu-ui-controls/src/tabstrip/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const Tab = forwardRef(function Tab(
<TabMenu
allowClose={closeable}
allowRename={editable}
controlledComponentId={ariaControls}
location={location}
onMenuAction={onMenuAction as MenuActionHandler}
onMenuClose={onMenuClose}
Expand Down
10 changes: 8 additions & 2 deletions vuu-ui/packages/vuu-ui-controls/src/tabstrip/TabMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ const classBase = "vuuTabMenu";
export interface TabMenuProps {
allowClose: boolean;
allowRename: boolean;
index: number;
location?: string;
onMenuAction: MenuActionHandler;
onMenuClose?: () => void;
index: number;
/**
* The id of associated component, if available
*/
controlledComponentId?: string;
}

export const TabMenu = ({
allowClose,
allowRename,
controlledComponentId,
location,
onMenuAction,
onMenuClose,
Expand All @@ -42,10 +47,11 @@ export const TabMenu = ({
return menuItems;
},
{
controlledComponentId,
tabIndex: index,
},
],
[allowClose, allowRename, index]
[allowClose, allowRename, controlledComponentId, index]
);

return (
Expand Down

0 comments on commit 6faa7f1

Please sign in to comment.