diff --git a/.github/workflows/nightly_lock.yaml b/.github/workflows/nightly_lock.yaml index e4be7855fb..4e93224379 100644 --- a/.github/workflows/nightly_lock.yaml +++ b/.github/workflows/nightly_lock.yaml @@ -9,13 +9,13 @@ env: jobs: pixi_lock: + if: ${{ !github.event.repository.fork }} name: Pixi lock runs-on: ubuntu-latest timeout-minutes: 5 steps: - uses: holoviz-dev/holoviz_tasks/pixi_lock@v0 - name: Upload lock-file to S3 - if: '!github.event.pull_request.head.repo.fork' env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 42da8c341f..f0c6a3fe39 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -101,7 +101,7 @@ jobs: run: | MATRIX=$(jq -nsc '{ "os": ["ubuntu-latest", "macos-latest", "windows-latest"], - "environment": ["test-310", "test-312"] + "environment": ["test-310", "test-313"] }') echo "MATRIX=$MATRIX" >> $GITHUB_ENV - name: Set test matrix with 'full' option @@ -109,7 +109,7 @@ jobs: run: | MATRIX=$(jq -nsc '{ "os": ["ubuntu-latest", "macos-latest", "windows-latest"], - "environment": ["test-310", "test-311", "test-312"] + "environment": ["test-310", "test-311", "test-312", "test-313"] }') echo "MATRIX=$MATRIX" >> $GITHUB_ENV - name: Set test matrix with 'downstream' option @@ -170,7 +170,7 @@ jobs: matrix: os: ["ubuntu-latest", "macos-latest", "windows-latest"] environment: ["test-ui"] - timeout-minutes: 120 + timeout-minutes: 60 env: PANEL_LOG_LEVEL: info OAUTH_COOKIE_SECRET: ${{ secrets.OAUTH_COOKIE_SECRET }} @@ -181,11 +181,6 @@ jobs: AUTH0_OAUTH_EXTRA_PARAMS: ${{ secrets.AUTH0_OAUTH_EXTRA_PARAMS }} AUTH0_OAUTH_USER: ${{ secrets.AUTH0_OAUTH_USER }} AUTH0_OAUTH_PASSWORD: ${{ secrets.AUTH0_OAUTH_PASSWORD }} - AZURE_PORT: "5702" - AZURE_OAUTH_KEY: ${{ secrets.AZURE_OAUTH_KEY }} - AZURE_OAUTH_SECRET: ${{ secrets.AZURE_OAUTH_SECRET }} - AZURE_OAUTH_USER: ${{ secrets.AZURE_OAUTH_USER }} - AZURE_OAUTH_PASSWORD: ${{ secrets.AZURE_OAUTH_PASSWORD }} OKTA_PORT: "5703" OKTA_OAUTH_KEY: ${{ secrets.OKTA_OAUTH_KEY }} OKTA_OAUTH_SECRET: ${{ secrets.OKTA_OAUTH_SECRET }} @@ -212,6 +207,10 @@ jobs: with: resource: http-get://localhost:8887/lab timeout: 180000 + - name: Check if auth should run + if: '!github.event.pull_request.head.repo.fork' + run: | + echo "PANEL_TEST_AUTH=1" >> $GITHUB_ENV - name: Test UI run: | # Create a .uicoveragerc file to set the concurrency library to greenlet @@ -243,8 +242,8 @@ jobs: fail-fast: false matrix: os: ["ubuntu-latest"] - environment: ["test-core", "test-minimum"] - timeout-minutes: 120 + environment: ["test-core", "test-bokeh35", "test-bokeh36"] + timeout-minutes: 30 steps: - uses: holoviz-dev/holoviz_tasks/pixi_install@v0 with: @@ -263,11 +262,12 @@ jobs: matrix: os: ["ubuntu-latest"] environment: ["test-type"] - timeout-minutes: 120 + timeout-minutes: 30 steps: - uses: holoviz-dev/holoviz_tasks/pixi_install@v0 with: environments: ${{ matrix.environment }} + install: false - name: Test Type run: | pixi run -e ${{ matrix.environment }} test-type diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1d019b4f9a..5753a08ddb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,29 +14,29 @@ repos: exclude: \.min\.js$ - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.6 + rev: v0.11.4 hooks: - id: ruff files: panel/ - repo: https://github.com/pycqa/isort - rev: 5.13.2 + rev: 6.0.1 hooks: - id: isort name: isort (python) - repo: https://github.com/hoxbro/clean_notebook - rev: v0.1.15 + rev: v0.1.17 hooks: - id: clean-notebook args: [-i, tags] exclude: '^lite/files/.*/' - repo: https://github.com/codespell-project/codespell - rev: v2.3.0 + rev: v2.4.1 hooks: - id: codespell additional_dependencies: - tomli - repo: https://github.com/hoxbro/prettier-pre-commit - rev: v3.4.2 + rev: v3.5.3 hooks: - id: prettier entry: prettier --write --ignore-unknown --no-error-on-unmatched-pattern @@ -47,7 +47,7 @@ repos: - id: oxipng stages: [manual] - repo: https://github.com/pre-commit/mirrors-eslint - rev: v9.17.0 + rev: v9.24.0 hooks: - id: eslint args: ['-c', 'panel/.eslintrc.js', 'panel/*.ts', 'panel/models/**/*.ts', '--fix'] diff --git a/CHANGELOG.md b/CHANGELOG.md index a7d4e6f22c..165799f9a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,202 @@ # Releases +## Version 1.7.1 + +This patch release adds a new option to disable `FileDropper` previews +and fixes a regression when updating `Column` children in Bokeh<3.7. +Additionally it includes a number of documentation improvements. +Many thanks to our returning contributors @dalthviz, @emmanuel-ferdman, @MarcSkovMadsen, and @hoxbro + +### Enhancements + +- Add option to disable FileDropper previews ([#7944](https://github.com/holoviz/panel/pull/7944)) +- `--index-titles` help string typo fix and don't call `title` on user input ([#7935](https://github.com/holoviz/panel/pull/7935)) + +### Bug fixes + +- Migrate to correct logger interface ([#7931](https://github.com/holoviz/panel/pull/7931)) +- Column updates not working for Bokeh<3.7 ([#7948](https://github.com/holoviz/panel/pull/7948)) + +### Documentation + +- Fix image links in Azure documentation ([#7938](https://github.com/holoviz/panel/pull/7938)) + + +## Version 1.7.0 + +This minor release is not as jam-packed as previous minor releases but adds a number of quality of life improvements, bug fixes and features along with version and compatibility updates for a number of JS dependencies. Many thanks to some of our more frequent contributors @dalthviz, @etihwo, our new contributor @emmanuel-ferdman and our maintainers @Hoxbro, @MarcSkovMadsen and @philippjfr. + +### Features + +- Add a secondary (right) sidebar to the `FastListTemplate` ([#7774](https://github.com/holoviz/panel/pull/7774)) +- Add `Date(Time)Picker.allowInput` option ([#7886](https://github.com/holoviz/panel/pull/7886)) +- Add `Markdown.disable_anchors` option ([#7902](https://github.com/holoviz/panel/pull/7902)) +- Add `config.cache_path` variable to configure default location for diskcache ([#7903](https://github.com/holoviz/panel/pull/7903)) +- Support custom cookie path ([#7911](https://github.com/holoviz/panel/pull/7911)) +- Allow customizing index page titles with `--index-titles` CLI option ([#7916](https://github.com/holoviz/panel/pull/7916)) +- Add `Image.target` option to configure where to open `link_url` ([#7924](https://github.com/holoviz/panel/pull/7924)) + +### Enhancements + +- Display parameter name in error messages ([#7879](https://github.com/holoviz/panel/pull/7879)) +- Improve Material design styling ([#7891](https://github.com/holoviz/panel/pull/7891), [#7917](https://github.com/holoviz/panel/pull/7917)) +- Improve logic for computing Tabulator page size automatically ([#7915](https://github.com/holoviz/panel/pull/7915)) + +### Versions and Compatibility + +- Bump Ace `CodeEditor` version 1.40.1 and add themes ([#7874](https://github.com/holoviz/panel/pull/7874)) +- Bump pyodide version to 0.27.5 ([#7905](https://github.com/holoviz/panel/pull/7905)) +- Bump `ECharts` version to 5.6.0 ([#7905](https://github.com/holoviz/panel/pull/7905)) +- Bump `JSONEditor` version to 10.2.0 ([#7905](https://github.com/holoviz/panel/pull/7905)) +- Bump `Perspective` version to 3.6.1 ([#7919](https://github.com/holoviz/panel/pull/7919)) + +### Bug fixes + +- Deduplicate components before compiling ([#7887](https://github.com/holoviz/panel/pull/7887)) +- Avoid boomeranging of events after `hold` is applied ([#7892](https://github.com/holoviz/panel/pull/7892)) +- Handle .ico image base64 mime-type correctly ([#7894](https://github.com/holoviz/panel/pull/7894)) +- Ensure `FileDropper` height is not limited ([#7898](https://github.com/holoviz/panel/pull/7898)) +- Ensure correct stylesheet cache is used by theme hooks when component is shared between sessions ([#7896](https://github.com/holoviz/panel/pull/7896)) +- Reset `BaseTemplate._documents` correctly on autoreload ([#7897](https://github.com/holoviz/panel/pull/7897)) +- Ensure widget CSS is loaded correctly when server path is prefixed ([#7900](https://github.com/holoviz/panel/pull/7900)) +- Correct display `Tabulator` with multi index and multi index column ([#7907](https://github.com/holoviz/panel/pull/7907)) +- Ensure stretch and scale sizing_mode does not cause overflow in container ([#7928](https://github.com/holoviz/panel/pull/7928)) + +### Documentation + +- Document caching of dependencies by combining `cache` with `depends` ([#7876](https://github.com/holoviz/panel/pull/7876)) +- Remove deprecated keyword in doc for `DateRangeSlider` and `DateTimeRangSlider` ([#7893](https://github.com/holoviz/panel/pull/7893)) +- Add guidance on troubleshooting OAuth issues ([#7921](https://github.com/holoviz/panel/pull/7921)) + +## Version 1.6.3 + +This release introduces a number of performance improvements related to rendering of children in layouts and ESM components, a number of bug fixes and a number of documentation improvements. We are pleased to welcome @malemburg as a new contributor and want to thank @s-alexey, @Coderambling, @etihwo and our core maintainer team including @hoxbro, @ahuang11, @MarcSkovMadsen and @philippjfr for their contributions to this release. + +### Enhancements + +- Implement smarter `Column` child rendering [#7846](https://github.com/holoviz/panel/pull/7846) +- Optimize `ReactComponent` child renders [#7828](https://github.com/holoviz/panel/pull/7828) +- Add `indent` and `soft_tabs` options to `CodeEditor` [#7831](https://github.com/holoviz/panel/pull/7831) +- Allow creating `Param.widget` without instantiating object, speeding up `Widget.from_param` [#7867](https://github.com/holoviz/panel/pull/7867) + +### Bug fixes + +- Fix handling of React based `AnyWidgetComponent` types [#7820](https://github.com/holoviz/panel/pull/7820) +- Cache ESM render modules [#7827](https://github.com/holoviz/panel/pull/7827) +- Check for `None` in `select` function for `PyComponent` [#7837](https://github.com/holoviz/panel/pull/7837) +- Fix for `AttributeError` in `auth.py:CodeChallenge` OAuth login [#7844](https://github.com/holoviz/panel/pull/7844) +- Fix error when `old_objects` is empty in `_get_objects()` [#7842](https://github.com/holoviz/panel/pull/7842) +- Ensure `ReactiveESM` renders elements [#7853](https://github.com/holoviz/panel/pull/7853) +- Ensure ESM shared resources are watched properly [#7856](https://github.com/holoviz/panel/pull/7856) +- Fix Material design `Tabulator` header color [#7855](https://github.com/holoviz/panel/pull/7855) +- Ensure current view and selection lookups on `Tabulator` handle `None` case [#7858](https://github.com/holoviz/panel/pull/7858) +- Ensure `Modal` events are targeted to correct model [#7860](https://github.com/holoviz/panel/pull/7860) +- Ensure `ChatFeed` has inherent height [#7861](https://github.com/holoviz/panel/pull/7861) +- Ensure `Markdown` code blocks are always left aligned [#7862](https://github.com/holoviz/panel/pull/7862) +- Gracefully handle `ECharts` delayed rendering [#7869](https://github.com/holoviz/panel/pull/7869) + +### Documentation + +- List version agnostic wheel URLs in WASM standalone docs [#7857](https://github.com/holoviz/panel/pull/7857) +- Correct `ClassSelector` keyword in `build_todo.md` [#7819](https://github.com/holoviz/panel/pull/7819) +- Fix documentation of `--oauth-extra-params` [#7865](https://github.com/holoviz/panel/pull/7865) +- Fix minor issues in FastAPI docs [#7866](https://github.com/holoviz/panel/pull/7866) +- Clarify OAuth redirect uri [#7868](https://github.com/holoviz/panel/pull/7868) +- Add section in load balancing about Bokeh extensions ([#7832](https://github.com/holoviz/panel/pull/7832)) + +## Version 1.6.2 + +This release primarily introduces improvements for ESM and React components and refactoring to make it easy to subclass existing components. This is an effort to make it easier to provide alternative implementations for Panel components. Additionally this release includes compatibility for Bokeh 3.7, bug fixes for `TextEditor` and a variety of other bug fixes. Many thanks to our new contributor @s-alexey, our returning contributors @Coderambling and the core maintainer team including @Hoxbro, @ahuang11 and @philippjfr. + +### Enhancements + +- Make it easier to subclass components ([#7730](https://github.com/holoviz/panel/pull/7730), [#7744](https://github.com/holoviz/panel/pull/7744), [#7785](https://github.com/holoviz/panel/pull/7785)) +- Allow `model.useState` in `ReactComponent`s to reference nested parameter values ([#7743](https://github.com/holoviz/panel/pull/7743)) +- Allow providing shared ESM modules ([#7757](https://github.com/holoviz/panel/pull/7757)) +- Allow defining root node for `ReactComponent` ([#7787](https://github.com/holoviz/panel/pull/7787)) +- Improve pretty printing in `HoloViews` pane ([#7775](https://github.com/holoviz/panel/pull/7775)) +- Allow serializing joint dict/Parameterized types on `DataModel` ([#7789](https://github.com/holoviz/panel/pull/7789)) +- Improve ListLike and NamedListLike to better match Python list behavior ([#7794](https://github.com/holoviz/panel/pull/7794)) +- Improve rendering of ReactComponent children ([#7802](https://github.com/holoviz/panel/pull/7802)) +- Allow overriding Param input widgets ([#7813](https://github.com/holoviz/panel/pull/7813)) + +### Performance + +- Avoid redundant list operations in ListLike ([#7764](https://github.com/holoviz/panel/pull/7764)) +- Optimize ipywidget reference transform ([#7778](https://github.com/holoviz/panel/pull/7778)) + +### Bug fixes + +- Correctly handle empty source files ([#7732](https://github.com/holoviz/panel/pull/7732)) +- Add extra guard around `get_ipython` check ([#7734](https://github.com/holoviz/panel/pull/7734)) +- Ensure `ReactComponent` children are sized correctly ([#7741](https://github.com/holoviz/panel/pull/7741)) +- Ensure `ChatStep` does not toggle from failed to success ([#7742](https://github.com/holoviz/panel/pull/7742)) +- Ensure `Feed` and scrollable layout children heights are not fixed ([#7747](https://github.com/holoviz/panel/pull/7747)) +- Declare more `Child` parameters on various components ([#7749](https://github.com/holoviz/panel/pull/7749)) +- Do not sync parameters mapped to None on on ESM components ([#7750](https://github.com/holoviz/panel/pull/7750), [#7753](https://github.com/holoviz/panel/pull/7753)) +- Always include esm.css for ESM components ([#7752](https://github.com/holoviz/panel/pull/7752)) +- Do not duplicate stylesheets (d133eb9) +- Ensure `ChatStep` text does not overflow container ([#7770](https://github.com/holoviz/panel/pull/7770)) +- Refactor `ChatFeed` post hook ensuring it processes correct message ([#7722](https://github.com/holoviz/panel/pull/7722)) +- Ensure hooks are applied to root components with `Fast` design ([#7777](https://github.com/holoviz/panel/pull/7777)) +- Ensure resource mode is set in notebooks ([#7776](https://github.com/holoviz/panel/pull/7776)) +- Clear state cookie if OAuth access token expired and can't be refreshed ([#7780](https://github.com/holoviz/panel/pull/7780)) +- Fix formatting in `TextEditor` widget ([#7739](https://github.com/holoviz/panel/pull/7739)) +- Use Ace version with no require.js dependency ([#7781](https://github.com/holoviz/panel/pull/7781)) +- Ensure multiple sequential notifications render ([#7790](https://github.com/holoviz/panel/pull/7790)) +- Style correct column when frozen `Tabulator` column is an index ([#7792](https://github.com/holoviz/panel/pull/7792)) +- Ensure IconButton tooltip timer is cleared on multiple mouseenter events ([#7798](https://github.com/holoviz/panel/pull/7798)) +- Ensure pre-processors are applied to ESM children ([#7799](https://github.com/holoviz/panel/pull/7799)) +- Ensure outputs are laid out correctly after initial render of `EditableTemplate` ([#7816](https://github.com/holoviz/panel/pull/7816)) +- Fix regressiong related to providing Path to ESM component stylesheets ([#7809](https://github.com/holoviz/panel/pull/7809)) + +### Compatibility + +- Compatibility with Bokeh 3.7 ([#7724](https://github.com/holoviz/panel/pull/7724), [#7815](https://github.com/holoviz/panel/pull/7815)) +- Update `TextEditor` widget to Quill.js 2.0.2 ([#7739](https://github.com/holoviz/panel/pull/7739)) +- Update `Plotly` pane to Plotly.js 3.0.1 ([#7731](https://github.com/holoviz/panel/pull/7731)) + +### Documentation + +- Incorrect hover text for max_width and max_height: both said Minimum instead of Maximum ([#7729](https://github.com/holoviz/panel/pull/7729)) +- Various minor documentation updates ([#7719](https://github.com/holoviz/panel/pull/7719), [#7738](https://github.com/holoviz/panel/pull/7738), [#7746](https://github.com/holoviz/panel/pull/7746), [#7755](https://github.com/holoviz/panel/pull/7755), [#7760](https://github.com/holoviz/panel/pull/7760), [#7761](https://github.com/holoviz/panel/pull/7761), [#7763](https://github.com/holoviz/panel/pull/7763)) + +## Version 1.6.1 + +This patch release primarily addresses issues running Panel behind a reverse proxy, improves the developer experience of working with custom ESM bundles and adds compatibility for Plotly 6.0. Congratulations to @fabiovincenzi and @pankajp for their first contribution fixing inlining of stylesheets. Many thanks to to our returning contributors @ceball, @Azaya89 and @Coderambling as well as our core developer team including @ahuang11, @Maximlt, @hoxbro and @philippjfr for contributing to this release. + +### Enhancements + +- Add `ChatFeed.scroll_to` method ([#7671](https://github.com/holoviz/panel/pull/7671)) +- Implement watch feature for `panel compile` command ([#7683](https://github.com/holoviz/panel/pull/7683)) +- Allow ESM components to load CSS bundles ([#7685](https://github.com/holoviz/panel/pull/7685), [#7691](https://github.com/holoviz/panel/pull/7691)) +- Generalize `ReactiveESM.select` so children are automatically detected ([#7699](https://github.com/holoviz/panel/pull/7699)) + +### Bug fixes + +- Ensure errors in sync periodic callbacks are logged ([#7665](https://github.com/holoviz/panel/pull/7665)) +- Reset `visible_range` when `Feed.objects` are updated ([#7673](https://github.com/holoviz/panel/pull/7673)) +- Ensure ESM bundles correctly resolve component implementations ([#7684](https://github.com/holoviz/panel/pull/7684), [#7698](https://github.com/holoviz/panel/pull/7698)) +- Fix default avatar in send/stream ([#7677](https://github.com/holoviz/panel/pull/7677)) +- Ensure index redirects are relative to fix index page behind a reverse proxy ([#7704](https://github.com/holoviz/panel/pull/7704)) +- Ensure root_url is correctly determined during auth ([#7680](https://github.com/holoviz/panel/pull/7680)) +- Ensure the modal is on top in EditableTemplate ([#7710](https://github.com/holoviz/panel/pull/7710)) +- Ensure Tabulator selection is recalculated after filtering ([#7712](https://github.com/holoviz/panel/pull/7712)) +- Fix custom login endpoints ([#7714](https://github.com/holoviz/panel/pull/7714)) +- Ensure type checkers can correctly infer extension argument types ([#7709](https://github.com/holoviz/panel/pull/7709)) +- Ensure custom components and extensions respect resource mode in notebooks ([#7701](https://github.com/holoviz/panel/pull/7701), [#7716](https://github.com/holoviz/panel/pull/7716)) +- Ensure in process events are cleaned up after they are applied ([#7717](https://github.com/holoviz/panel/pull/7717)) + +### Compatibility + +- Compatibility with Plotly 6.0 ([#7681](https://github.com/holoviz/panel/pull/7681), [#7682](https://github.com/holoviz/panel/pull/7682)) +- Bump pyodide version to 0.27.2 and PyScript version to 2025.2.1 ([#7718](https://github.com/holoviz/panel/pull/7718)) + +### Docs + +- Add links to other HoloViz libraries to the sidebar ([#7674](https://github.com/holoviz/panel/pull/7674)) +- Minor documentation fixes ([#7664](https://github.com/holoviz/panel/pull/7664), [#7668](https://github.com/holoviz/panel/pull/7668), [#7692](https://github.com/holoviz/panel/pull/7692)) + ## Version 1.6.0 This release adds a number of features including a standalone `Modal` component, the ability to infer widget parameters from values, and the ability to easily edit a `ChatMessage`. Additionally it includes a number of enhancements for styling, particularly in dark themes, other enhancements for chat components and a large number of bug fixes. Many thanks for our returning contributor @kdheepak, our new contributors @pgierz, @jonatantreijs and @etihwo, and of course the whole maintainer team including @ahuang11, @MarcSkovMadsen @hoxbro, @maximlt and @philippjfr. diff --git a/doc/_static/images/azure_oauth_app_registration.png b/doc/_static/images/azure_oauth_app_registration.png new file mode 100644 index 0000000000..1e3a0bd19f Binary files /dev/null and b/doc/_static/images/azure_oauth_app_registration.png differ diff --git a/doc/_static/images/azure_oauth_client_secret.png b/doc/_static/images/azure_oauth_client_secret.png new file mode 100644 index 0000000000..f69d55a86b Binary files /dev/null and b/doc/_static/images/azure_oauth_client_secret.png differ diff --git a/doc/_static/images/azure_oauth_uris.png b/doc/_static/images/azure_oauth_uris.png new file mode 100644 index 0000000000..52a5b35ee7 Binary files /dev/null and b/doc/_static/images/azure_oauth_uris.png differ diff --git a/doc/_static/images/oauth_debugging.png b/doc/_static/images/oauth_debugging.png new file mode 100644 index 0000000000..f6b319cb0c Binary files /dev/null and b/doc/_static/images/oauth_debugging.png differ diff --git a/doc/_static/toggle.js b/doc/_static/toggle.js deleted file mode 100644 index d49442cf13..0000000000 --- a/doc/_static/toggle.js +++ /dev/null @@ -1,97 +0,0 @@ -function clone(node) { - var new_element = node.cloneNode(true); - node.parentNode.replaceChild(new_element, node); - return new_element -} - -function documentReady(callback) { - if (document.readyState != "loading") callback(); - else document.addEventListener("DOMContentLoaded", callback); -} - -let loaded = false - -function setupMobileSidebarKeyboardHandlers() { - if (loaded) { - return - } - loaded = true - - // These are hidden checkboxes at the top of the page whose :checked property - // allows the mobile sidebars to be hidden or revealed via CSS. - const primaryToggle = document.getElementById("pst-primary-sidebar-checkbox"); - const secondaryToggle = document.getElementById( - "pst-secondary-sidebar-checkbox", - ); - const primarySidebar = document.querySelector(".bd-sidebar-primary"); - const secondarySidebar = document.querySelector(".bd-sidebar-secondary"); - - // Toggle buttons - - // - // These are the hamburger-style buttons in the header nav bar. When the user - // clicks, the button transmits the click to the hidden checkboxes used by the - // CSS to control whether the sidebar is open or closed. - const primaryClickTransmitter = document.querySelector(".primary-toggle"); - const secondaryClickTransmitter = document.querySelector(".secondary-toggle"); - [ - [primaryClickTransmitter, primaryToggle, primarySidebar], - [secondaryClickTransmitter, secondaryToggle, secondarySidebar], - ].forEach(([clickTransmitter, toggle, sidebar]) => { - if (!clickTransmitter) { - return; - } - const cloned = clone(clickTransmitter) - cloned.addEventListener("click", (event) => { - event.preventDefault(); - event.stopPropagation(); - toggle.checked = !toggle.checked; - - // If we are opening the sidebar, move focus to the first focusable item - // in the sidebar - if (toggle.checked) { - // Note: this selector is not exhaustive, and we may need to update it - // in the future - const tabStop = sidebar.querySelector("a, button"); - // use setTimeout because you cannot move focus synchronously during a - // click in the handler for the click event - setTimeout(() => tabStop.focus(), 100); - } - }); - }); - - // Escape key - - // - // When sidebar is open, user should be able to press escape key to close the - // sidebar. - [ - [primarySidebar, primaryToggle, primaryClickTransmitter], - [secondarySidebar, secondaryToggle, secondaryClickTransmitter], - ].forEach(([sidebar, toggle, transmitter]) => { - if (!sidebar) { - return; - } - sidebar.addEventListener("keydown", (event) => { - if (event.key === "Escape") { - event.preventDefault(); - event.stopPropagation(); - toggle.checked = false; - transmitter.focus(); - } - }); - }); - - // When the