diff --git a/README.md b/README.md index cae15bb310..140d20c036 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,7 @@ You can use all of the following options with standalone version on tag * `disableSearch` - disable search indexing and search box * `onlyRequiredInSamples` - shows only required fields in request samples. * `jsonSampleExpandLevel` - set the default expand level for JSON payload samples (responses and request body). Special value 'all' expands all levels. The default value is `2`. +* `menuToggle` - if true clicking second time on expanded menu item will collapse it, default `false` * `theme` - ReDoc theme. Not documented yet. For details check source code: [theme.ts](https://github.com/Redocly/redoc/blob/master/src/theme.ts) ## Advanced usage of standalone version diff --git a/src/components/SideMenu/SideMenu.tsx b/src/components/SideMenu/SideMenu.tsx index e4dfe2c825..346430542b 100644 --- a/src/components/SideMenu/SideMenu.tsx +++ b/src/components/SideMenu/SideMenu.tsx @@ -2,6 +2,7 @@ import { observer } from 'mobx-react'; import * as React from 'react'; import { IMenuItem, MenuStore } from '../../services/MenuStore'; +import { OptionsContext } from '../OptionsProvider'; import { MenuItems } from './MenuItems'; import { PerfectScrollbarWrap } from '../../common-elements/perfect-scrollbar'; @@ -9,6 +10,7 @@ import { RedocAttribution } from './styled.elements'; @observer export class SideMenu extends React.Component<{ menu: MenuStore; className?: string }> { + static contextType = OptionsContext; private _updateScroll?: () => void; render() { @@ -32,6 +34,10 @@ export class SideMenu extends React.Component<{ menu: MenuStore; className?: str } activate = (item: IMenuItem) => { + if (item && item.active && this.context.menuToggle) { + return item.expanded ? item.collapse() : item.expand(); + } + this.props.menu.activateAndScroll(item, true); setTimeout(() => { if (this._updateScroll) { diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index e4bf6751bd..1bcffb275b 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -22,6 +22,7 @@ export interface RedocRawOptions { onlyRequiredInSamples?: boolean | string; showExtensions?: boolean | string | string[]; hideSingleRequestSampleTab?: boolean | string; + menuToggle?: boolean | string; jsonSampleExpandLevel?: number | string | 'all'; unstable_ignoreMimeParameters?: boolean; @@ -137,6 +138,7 @@ export class RedocNormalizedOptions { onlyRequiredInSamples: boolean; showExtensions: boolean | string[]; hideSingleRequestSampleTab: boolean; + menuToggle: boolean; jsonSampleExpandLevel: number; enumSkipQuotes: boolean; @@ -170,6 +172,7 @@ export class RedocNormalizedOptions { this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples); this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions); this.hideSingleRequestSampleTab = argValueToBoolean(raw.hideSingleRequestSampleTab); + this.menuToggle = argValueToBoolean(raw.menuToggle); this.jsonSampleExpandLevel = RedocNormalizedOptions.normalizeJsonSampleExpandLevel( raw.jsonSampleExpandLevel, );