Skip to content

feat($theme-default) Propagate toggleSidebar event to parent #1816

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

Merged
merged 2 commits into from
Sep 12, 2019

Conversation

shortdiv
Copy link
Contributor

Summary
The toggleSidebar event was not being propagated up from the NavBar component. This PR emits that event up to parent elements, so applications have access to the state of whether the side bar is open.

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

If changing the UI of default theme, please provide the before/after screenshot:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)

You have tested in the following browsers: (Providing a detailed version will be better.)

  • Chrome
  • Firefox
  • Safari
  • Edge
  • IE

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature
  • Related documents have been updated
  • Related tests have been updated

To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.

Other information:

@kefranabg
Copy link
Collaborator

Hi @shortdiv,

Why would you need to do catch this event? Could you provide a concrete example?

@shortdiv
Copy link
Contributor Author

shortdiv commented Sep 3, 2019

Hey! Sure thing! It seems that the body of the docs content scrolls even when the sidebar is open, which makes for a pretty janky experience. If the toggle sidebar state is bubbled up, you can easily add and remove an overflow property to the body via the layout component.

<template>
  <Layout @toggle-sidebar="controlBodyScroll">
    ...
  </Layout>
</template>
<script>
import Layout from "@parent-theme/layouts/Layout.vue";

export default {
  components: { Layout },
  methods: {
    controlBodyScroll(isSidebarOpen) {
      if (!isSidebarOpen) {
        document.body.style.overflow = "hidden";
      } else {
        document.body.style.overflow = "auto";
      }
    }
  }
}
</script>

@flozero flozero added need feedback Awaiting author response status: community assigned Community assigned topic: theme Relates to VuePress theme type: enhancement Request to enhance an existing feature version: 1.x Relates to version 1 of VuePress labels Sep 5, 2019
@shortdiv shortdiv requested a review from kefranabg September 5, 2019 19:56
@kefranabg kefranabg changed the title fix: Bubble toggleSidebar event to parent feat($theme-default) Propagate toggleSidebar event to parent Sep 12, 2019
@kefranabg kefranabg merged commit e8064b0 into vuejs:master Sep 12, 2019
@vue-bot
Copy link

vue-bot commented Sep 12, 2019

Hey @shortdiv, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need feedback Awaiting author response status: community assigned Community assigned topic: theme Relates to VuePress theme type: enhancement Request to enhance an existing feature version: 1.x Relates to version 1 of VuePress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants