Ensure ArgsTable state is reset when switching stories

This commit is contained in:
Gert Hengeveld 2021-04-06 21:40:38 +02:00
parent bc3702365f
commit 53c9df204f

View File

@ -1,5 +1,5 @@
import React, { FC } from 'react';
import { ArgTypes, useArgs, useArgTypes, useParameter } from '@storybook/api';
import { ArgTypes, useArgs, useArgTypes, useParameter, useStorybookState } from '@storybook/api';
import { ArgsTable, NoControlsWarning, PresetColor, SortType } from '@storybook/components';
import { PARAM_KEY } from './constants';
@ -21,6 +21,7 @@ export const ControlsPanel: FC = () => {
presetColors,
hideNoControlsWarning = false,
} = useParameter<ControlsParameters>(PARAM_KEY, {});
const { path } = useStorybookState();
const hasControls = Object.values(rows).some((arg) => arg?.control);
const showWarning = !(hasControls && isArgsStory) && !hideNoControlsWarning;
@ -36,6 +37,7 @@ export const ControlsPanel: FC = () => {
{showWarning && <NoControlsWarning />}
<ArgsTable
{...{
key: path, // resets state when switching stories
compact: !expanded && hasControls,
rows: withPresetColors,
args,