Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toolbars: Fix title behavior in UI #22496

Merged
merged 4 commits into from
May 10, 2023
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
13 changes: 4 additions & 9 deletions code/addons/toolbars/src/components/ToolbarMenuList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { FC } from 'react';
import React, { useState, useCallback } from 'react';
import { useGlobals } from '@storybook/manager-api';
import { deprecate } from '@storybook/client-logger';
import { WithTooltip, TooltipLinkList } from '@storybook/components';
import { ToolbarMenuButton } from './ToolbarMenuButton';
import type { WithKeyboardCycleProps } from '../hoc/withKeyboardCycle';
Expand Down Expand Up @@ -31,18 +30,14 @@ export const ToolbarMenuList: FC<ToolbarMenuListProps> = withKeyboardCycle(
icon = getSelectedIcon({ currentValue, items }) || icon;
}

// Deprecation support for old "name of global arg used as title"
if (!title) {
title = name;
deprecate(
'`showName` is deprecated as `name` will stop having dual purposes in the future. Please specify a `title` in `globalTypes` instead.'
);
}

if (dynamicTitle) {
title = getSelectedTitle({ currentValue, items }) || title;
}

if (!title && !icon) {
console.warn(`Toolbar '${name}' has no title or icon`);
}

const handleItemClick = useCallback(
(value: string | undefined) => {
updateGlobals({ [id]: value });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const ToolbarMenuListItem = ({
const Icon = icon && <Icons style={{ opacity: 1 }} icon={icon} />;

const Item: TooltipLinkListLink = {
id: value || currentValue,
id: value ?? '_reset',
active: currentValue === value,
right,
title,
Expand Down
4 changes: 3 additions & 1 deletion code/addons/toolbars/src/utils/get-selected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ interface GetSelectedItemProps {
}

export const getSelectedItem = ({ currentValue, items }: GetSelectedItemProps) => {
const selectedItem = currentValue != null && items.find((item) => item.value === currentValue);
const selectedItem =
currentValue != null &&
items.find((item) => item.value === currentValue && item.type !== 'reset');
return selectedItem;
};

Expand Down