cssvue.jselement-ui

How to open a element-ui drawer in a div as opposed to window


I'm trying to get a drawer to pop up within a div as opposed to using the full available window.

var Main = {
    data() {
      return {
        drawer: false,
        direction: 'rtl',
      };
    }
  };
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
@import url("//unpkg.com/element-ui@2.13.2/lib/theme-chalk/index.css");

.drawer-container{
  height: 600px;
  width: 600px;
  border: 1px solid red;
}
.drawer{
  height: 100%;
}
<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/element-ui@2.13.2/lib/index.js"></script>
<div id="app">
<el-radio-group v-model="direction">
  <el-radio label="ltr">left to right</el-radio>
  <el-radio label="rtl">right to left</el-radio>
  <el-radio label="ttb">top to bottom</el-radio>
  <el-radio label="btt">bottom to top</el-radio>
</el-radio-group>

<el-button @click="drawer = true" type="primary" style="margin-left: 16px;">
  open
</el-button>
<div class="drawer-container">
  <el-drawer
    class="drawer"
    title="I am the title"
    :visible.sync="drawer"
    :direction="direction">
    <span>Hi, there!</span>
  </el-drawer>
  </div>
</div>

The problem I have is that the drawer seems to have complete disregard to what it's parents css is. Anyone know a way of changing this?


Solution

  • Turns out this was as simple as adding position: relative

    var Main = {
        data() {
          return {
            drawer: false,
            direction: 'rtl',
          };
        }
      };
    var Ctor = Vue.extend(Main)
    new Ctor().$mount('#app')
    @import url("//unpkg.com/element-ui@2.13.2/lib/theme-chalk/index.css");
    
    .drawer-container{
      height: 600px;
      width: 600px;
      border: 1px solid red;
    }
    .drawer{
      position: relative;
      height: 100%;
    }
    <script src="//unpkg.com/vue/dist/vue.js"></script>
    <script src="//unpkg.com/element-ui@2.13.2/lib/index.js"></script>
    <div id="app">
    <el-radio-group v-model="direction">
      <el-radio label="ltr">left to right</el-radio>
      <el-radio label="rtl">right to left</el-radio>
      <el-radio label="ttb">top to bottom</el-radio>
      <el-radio label="btt">bottom to top</el-radio>
    </el-radio-group>
    
    <el-button @click="drawer = true" type="primary" style="margin-left: 16px;">
      open
    </el-button>
    <div class="drawer-container">
      <el-drawer
        class="drawer"
        title="I am the title"
        :visible.sync="drawer"
        :direction="direction">
        <span>Hi, there!</span>
      </el-drawer>
      </div>
    </div>