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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"@types/react": "^19.2.14",
"@types/semver": "^7.7.1",
"@types/shelljs": "^0.8.12",
"@vitejs/plugin-react": "^5.0.0",
"@vitejs/plugin-react": "^6.0.2",
"@vitest/eslint-plugin": "^1.6.17",
"cross-env": "^10.1.0",
"cspell": "^8.18.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-docusaurus/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {logger} from '@docusaurus/logger';
import semver from 'semver';
import {program} from 'commander';

const packageJson = /** @type {import("../package.json")} */ (
const packageJson = /** @type {typeof import("../package.json")} */ (
createRequire(import.meta.url)('../package.json')
);
const requiredVersion = packageJson.engines.node;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// @vitest-environment jsdom
import {describe, expect, it, vi} from 'vitest';
import React from 'react';
import {render, act, fireEvent} from '@testing-library/react';
import {Details} from '../index';

function renderDetails(props: {open?: boolean} = {}) {
const {container} = render(
<Details summary="the summary" {...props}>
the content
</Details>,
);
return container.querySelector('details')!;
}

// jsdom doesn't fire the native toggle event on open changes: simulate the
// browser behavior manually
function setOpenExternally(details: HTMLDetailsElement, open: boolean) {
act(() => {
details.open = open;
details.dispatchEvent(new Event('toggle'));
});
}

describe('Details', () => {
// Fix jsdom not implementing matchMedia()
// See https://github.com/jsdom/jsdom/issues/3522
// Used through Details > Collapsible > getAutoHeightDuration()
vi.stubGlobal('matchMedia', () => {
return {matches: true};
});

it('renders collapsed by default', () => {
const details = renderDetails();
expect(details.open).toBe(false);
expect(details.dataset.collapsed).toBe('true');
});

it('renders expanded with open prop', () => {
const details = renderDetails({open: true});
expect(details.open).toBe(true);
expect(details.dataset.collapsed).toBe('false');
});

it('expands when clicking the summary', () => {
const details = renderDetails();
fireEvent.click(details.querySelector('summary')!);
expect(details.open).toBe(true);
expect(details.dataset.collapsed).toBe('false');
});

it('expands when the open attribute is set externally', () => {
// See https://github.com/facebook/docusaurus/issues/10140
const details = renderDetails();
setOpenExternally(details, true);
expect(details.open).toBe(true);
expect(details.dataset.collapsed).toBe('false');
});

it('collapses when the open attribute is removed externally', () => {
const details = renderDetails({open: true});
setOpenExternally(details, false);
expect(details.open).toBe(false);
expect(details.dataset.collapsed).toBe('true');
});
});
10 changes: 10 additions & 0 deletions packages/docusaurus-theme-common/src/components/Details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ export function Details({
// Don't do this, it breaks close animation!
// setOpen(false);
}
}}
onToggle={(e) => {
// The toggle event also fires when React syncs the open attribute
// See https://github.com/facebook/docusaurus/pull/12277
const isOpen = e.currentTarget.open;
if (isOpen === !collapsed) {
return;
}
setCollapsed(!isOpen);
setOpen(isOpen);
}}>
{summaryElement}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"theme.Playground.liveEditor": "Edytor live",
"theme.Playground.buttons.reset": "Reset",
"theme.Playground.buttons.reset": "Resetuj",
"theme.Playground.result": "Rezultat"
}
2 changes: 1 addition & 1 deletion packages/docusaurus-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@
"@types/micromatch": "^4.0.10",
"@types/js-yaml": "^4.0.9",
"@types/react-dom": "^19.2.3",
"dedent": "^0.7.0"
"dedent": "^1.7.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,17 @@ describe('escapeMarkdownHeadingIds', () => {
###### title 6 {#id-6}
`),
).toEqual(dedent`
# title 1 \{#id-1}
# title 1 \\{#id-1}

## title 2 \{#id-2}
## title 2 \\{#id-2}

### title 3 \{#id-3}
### title 3 \\{#id-3}

#### title 4 \{#id-4}
#### title 4 \\{#id-4}

##### title 5 \{#id-5}
##### title 5 \\{#id-5}

###### title 6 \{#id-6}
###### title 6 \\{#id-6}
`);
});

Expand Down Expand Up @@ -294,7 +294,7 @@ describe('escapeMarkdownHeadingIds', () => {

Stack Overflow is a popular forum to ask code-level questions or if you're stuck with a specific error. Read through the [existing questions](https://stackoverflow.com/questions/tagged/docusaurus) tagged with **docusaurus** or [ask your own](https://stackoverflow.com/questions/ask?tags=docusaurus)!

## Discussion forums \{#discussion-forums}
## Discussion forums \\{#discussion-forums}

There are many online forums for discussion about best practices and application architecture as well as the future of Docusaurus. If you have an answerable code-level question, Stack Overflow is usually a better fit.

Expand All @@ -320,11 +320,11 @@ describe('escapeMarkdownHeadingIds', () => {

Before participating in Docusaurus' communities, [please read our Code of Conduct](https://engineering.fb.com/codeofconduct/). We have adopted the [Contributor Covenant](https://www.contributor-covenant.org/) and we expect that all community members adhere to the guidelines within.

## Stack Overflow \{#stack-overflow}
## Stack Overflow \\{#stack-overflow}

Stack Overflow is a popular forum to ask code-level questions or if you're stuck with a specific error. Read through the [existing questions](https://stackoverflow.com/questions/tagged/docusaurus) tagged with **docusaurus** or [ask your own](https://stackoverflow.com/questions/ask?tags=docusaurus)!

## Discussion forums \{#discussion-forums}
## Discussion forums \\{#discussion-forums}

There are many online forums for discussion about best practices and application architecture as well as the future of Docusaurus. If you have an answerable code-level question, Stack Overflow is usually a better fit.

Expand All @@ -333,11 +333,11 @@ describe('escapeMarkdownHeadingIds', () => {
- [#contributors](https://discord.gg/6g6ASPA) for contributing help
- [Reddit's Docusaurus community](https://www.reddit.com/r/docusaurus/)

## Feature requests \{#feature-requests}
## Feature requests \\{#feature-requests}

For new feature requests, you can create a post on our [feature requests board (Canny)](/feature-requests), which is a handy tool for road-mapping and allows for sorting by upvotes, which gives the core team a better indicator of what features are in high demand, as compared to GitHub issues which are harder to triage. Refrain from making a Pull Request for new features (especially large ones) as someone might already be working on it or will be part of our roadmap. Talk to us first!

## News \{#news}
## News \\{#news}

For the latest news about Docusaurus, [follow **@docusaurus** on X](https://x.com/docusaurus) and the [official Docusaurus blog](/blog) on this website.
`);
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/bin/beforeCli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import updateNotifier from 'update-notifier';
import boxen from 'boxen';
import {DOCUSAURUS_VERSION} from '@docusaurus/utils';

const packageJson = /** @type {import("../package.json")} */ (
const packageJson = /** @type {typeof import("../package.json")} */ (
createRequire(import.meta.url)('../package.json')
);
/** @type {Record<string, any>} */
Expand Down
Loading
Loading