简体   繁体   English

样式材料Vue AutoComplete建议下拉列表

[英]Styling Material Vue AutoComplete suggestion drop down

Background 背景

I am using the Material Vue AutoComplete component to provide TypeAhead functionality to my users in a vue application. 我正在使用Material Vue AutoComplete组件在vue应用程序中为我的用户提供TypeAhead功能。

When the Chrome browser is minimized in width to check for responsiveness I noticed the suggestion container gets smaller in width but, the text inside of the suggestion container does not break in the box. 当Chrome浏览器的宽度最小化以检查响应性时,我注意到建议容器的宽度变小但是,建议容器内的文本没有在框中打破。 Instead, the sentence that is being displayed runs off the box to the right of the screen. 相反,正在显示的句子在屏幕右侧的框中运行。

Problem 问题

I can not figure out how to add styles to correct the before mentioned issue. 我无法弄清楚如何添加样式来纠正前面提到的问题。

Example

<div class="md-layout md-gutter">
<div class="md-layout-item md-small-size-100">
<md-autocomplete 
  v-model="currentCustomer"
  :md-options="customers" 
  @md-changed="getCustomers" 
  @md-opened="getCustomers"
  @md-selected="getSelected"
  :md-fuzzy-search="false"
 >
 <label>Search Customers...</label>
 <template slot="md-autocomplete-item" slot-scope="{ item, term }">
 <md-highlight-text :md-term="term">{{ item.email }}</md-highlight-text>
 </template>
<template slot="md-autocomplete-empty" slot-scope="{ term }">
 No customers matching "{{ term }}" were found. <a @click="addSearchedCustomer(term)">Create </a>this customer.
</template>
</md-autocomplete>
</div>

Specifically this line runs off the screen when there are no search results, 特别是当没有搜索结果时,此行会在屏幕外运行,

<template slot="md-autocomplete-empty" slot-scope="{ term }"> No customers matching "{{ term }}" were found. <a @click="addSearchedCustomer(term)">Create </a>this customer.</template>

Image Example 图像示例

在此输入图像描述

在此输入图像描述

Link AutoComplete 链接自动完成

UPDATE What I have tried 更新 我尝试过的

When I inspect the AutoComplete with Chrome Dev Tools, I expand the div and this is what it looks like, 当我使用Chrome开发工具检查自动完成时,我展开div,这就是它的样子,

Suggestion Container Div - 建议容器部 -

在此输入图像描述

Question

Looking at the documentation I can not seem to find a way to handle this. 看看文档,我似乎无法找到解决这个问题的方法。 How can I apply styles to this suggestion box so it will break the text as the screen gets smaller? 如何将样式应用于此建议框,以便在屏幕变小时打破文本?

The templated slot does not appear to respond to word-wrap styling (but other styles like color do work). 模板化的插槽似乎不响应自动换行样式(但其他样式如颜色可以工作)。

One way, a bit hacky, is to use a <label style="white-space: pre-wrap;"> to get a muli-line label, and use a directive to set the height. 一种方法,有点hacky,是使用<label style="white-space: pre-wrap;">来获取多线标签,并使用指令来设置高度。

template 模板

<md-autocomplete v-model="value" :md-options="colors">
  <label>Color</label>

  <template slot="md-autocomplete-item" slot-scope="{ item, term }">
    <span class="color" :style="`background-color: ${item.color}`"></span>
    <label v-wrapit
      style="white-space: pre-wrap;" 
      >{{item.name}}</label>
  </template>

  <template slot="md-autocomplete-empty" slot-scope="{ term }">
    <label v-wrapit 
      style="white-space: pre-wrap;" 
      >No colors matching "{{ term }}" were found</label>
  </template>

directive 指示

<script>
  export default {
    name: 'AutocompleteTemplate',
    directives: {
      wrapit: {
        inserted: function (el, binding, vnode) {
          el.style.height = `${el.scrollHeight}px`
          el.style.color = 'red'
          console.log('el', el.scrollHeight, el.offsetHeight, el)
        }
      }
    },
    data: () => ({
      value: null,
      colors: [
        { name: 'Aqua blue blue blue blue blue', color: '#00ffff' },
        { name: 'Aquamarine blue', color: '#7fffd4' },
      ]
    }),

style 样式

This style sets overall list width. 此样式设置整体列表宽度。 It is non-scoped because the menu appears outside <div id="app"> 它是非范围的,因为菜单出现在<div id="app">

<style>
  .md-menu-content {
    width: 200px !important;
  }
</style>

Here is a CodeSandbox to play with. 这是一个可以使用的CodeSandbox

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM