Skip to content
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

Take children with 'position: absolute;' into account #1

Open
alxppp opened this issue Apr 30, 2018 · 2 comments
Open

Take children with 'position: absolute;' into account #1

alxppp opened this issue Apr 30, 2018 · 2 comments

Comments

@alxppp
Copy link

alxppp commented Apr 30, 2018

Is it possible to also account for the height of children with position: absolute? Right now their height is ignored.

@alxppp
Copy link
Author

alxppp commented Apr 30, 2018

This is how I do it right now:

<template lang="pug">
div(ref="container", :style="{ height: height }")
  slot

</template>

<script>
export default {
  name: 'autoheight',
  data() {
    return {
      height: 'auto',
    };
  },
  computed: {
    computedHeight() {
      return this.height;
    },
  },
  methods: {
    maxChildHeight() {
      const children = this.$refs.container.children;
      return Math.max(Array.from(children).map(c => c.clientHeight));
    },
    updateHeight() {
      const container = window.getComputedStyle(this.$refs.container, null);
      const padding = parseFloat(container.getPropertyValue('padding-top')) +
          parseFloat(container.getPropertyValue('padding-bottom'));
      this.height = `${this.maxChildHeight() + padding}px`;
    },
  },
  mounted() {
    this.updateHeight();
    window.addEventListener('resize', this.updateHeight);
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.updateHeight);
  },
};
</script>

@guanzo
Copy link
Owner

guanzo commented May 1, 2018

I'm hesitant to add it as default functionality, perhaps the checks can be enabled through a boolean option?
Something like

this.$registerSmoothElement({
    el: this.$refs.container,
    containsAbsolute: true
})

Another cause for concern is that your code only checks the containers direct children. It obviously suits your needs but absolutely positioned children could be at arbitrary levels of nesting. Tell me your thoughts and I can get started on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants