Polymer 1.x:样式禁用纸张输入

时间:2016-11-03 07:00:21

标签: polymer polymer-1.0 paper-elements jsbin polymer-1.x

我想将<paper-input disabled ...元素格式化为不显示disabled(即没有将文字减轻)。

下面是我的代码(and in this jsBin),我展示了到目前为止我尝试过的内容。

我怎样才能做到这一点? (请提供一个有效的演示。Ideally, a clone of the subject jsBin。)

http://jsbin.com/giguwoyoha/1/edit?html,output
<!doctype html>
<head>
  <meta charset="utf-8">
  <base href="https://polygit.org/components/">
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link href="polymer/polymer.html" rel="import">
  <link href="paper-input/paper-input.html" rel="import">
</head>
<body>

<dom-module id="x-element">

<template>
  <style>
    /* Here is what I have tried so far */
    paper-input[disabled] {
      --paper-input: {
        color: black;
      }
    }
    paper-input {
      --paper-input-disabled: {
        color: black;
      }
    }
    paper-input {
      --paper-input-container-disabled: {
        color: black;
      }
    }
    paper-input[disabled] {
      color: black;
    }
    *[disabled] {
      color: black;
    }
  </style>

  <paper-input value="This is enabled text. I want to format the below to look like this."></paper-input>
  <paper-input value="This is disabled text. I want to format this to look like the above."
    disabled></paper-input>

</template>

<script>
  (function(){
    Polymer({
      is: "x-element",
      properties: {},
    });
  })();
</script>

</dom-module>

<x-element></x-element>

</body>

3 个答案:

答案 0 :(得分:2)

<style>
:host paper-input[disabled] {
  --paper-input-container-input-color: red;
  --paper-input-container-disabled: {
    opacity: 1;
  }
}

答案 1 :(得分:1)

以下是有关如何正确应用mixins的示例。

<style>
    :host {
      --paper-input-container-disabled: {
        color: pink;
        background: red;
        border: 5px dashed orange;
      };
    }
    paper-input {
      @apply(--paper-input-container-disabled);
    }
</style>

答案 2 :(得分:0)

为了方便将来的用户here is a jsBin demo of the accepted answer

这是完整的代码:

http://jsbin.com/mexirubida/1/edit?html,output
<!doctype html>
<head>
  <meta charset="utf-8">
  <base href="https://polygit.org/components/">
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link href="polymer/polymer.html" rel="import">
  <link href="paper-input/paper-input.html" rel="import">
</head>
<body>

<dom-module id="x-element">

<template>
<style>
  :host paper-input[disabled] {
    --paper-input-container-input-color: red;
    --paper-input-container-disabled: {
      opacity: 1;
    }
  }
</style>
  <paper-input value="This is enabled text. I want to format the below to look like this."></paper-input>
  <paper-input value="This is disabled text. I want to format this to look like the above."
    disabled></paper-input>

</template>

<script>
  (function(){
    Polymer({
      is: "x-element",
      properties: {},
    });
  })();
</script>

</dom-module>

<x-element></x-element>

</body>

修改

以上工作在jsBin演示中。但是,在尝试将其添加到我的自定义元素时,我必须按如下方式修改代码:

:host {
  paper-input[disabled] {
    --paper-input-container-input-color: red;
    --paper-input-container-disabled: {
      opacity: 1;
    }
  }
}