移动设备上未显示选择选项

时间:2017-07-21 11:07:24

标签: css styled-components

使用react和styled-components我设法编写了一个小组件来提问并显示一个包含5个选项/开头的栏,供用户选择。

这是它应该是什么样子:

enter image description here

它在桌面上工作正常,但在移动浏览器(Android或IOS)上查看时,用户会看到:

enter image description here

以下是我的完整反应组件,任何想法我做错了什么?

import React, {Component} from 'react';
import styled from 'styled-components';
import _ from 'lodash';

class Question extends Component {
    constructor(props) {
        super(props);
        this.state = {
            value: props.value
        }
        this.handleChange = this.handleChange.bind(this);
    }
    handleChange(event) {
      this.setState({
          value: event.target.value
      });
      this.props.onChange(event);
    }
    render() {
      const {name, value, totalStars, caption} = this.props;
        return (
            <Container className="rateOptions">
                <Caption>{caption}</Caption>
                <Rating name={name} size={totalStars - 1} onChange={this.handleChange}>
                    {_.range(1, totalStars).reverse().map(function(object) {
                      if(object.toString() ===value)
                        return <option selected value={object.toString()} key={object.toString()}>☆</option>
                      return <option value={object.toString()} key={object.toString()}>☆</option>
                    })}
                </Rating>
                <RateValue>
                    {this.state.value}
                    / 5
                </RateValue>
            </Container>
        );
    }
}
export default Question;

const Rating = styled.select `
  background: none;
  font-size:30px;
  color: gold;
  unicode-bidi: bidi-override;
  direction: rtl;
  text-align: center;
  overflow: hidden;
  margin: 10px 0;
  height: 35px;
  outline: 0;
  border:none;
  float: left;
  -webkit-appearance: none;
  -moz-appearance: none;
  > option {
    display: inline-block;
    position: relative;
    cursor: pointer;
  }
  > option:hover, > option:hover ~ option, > option:checked, > option:checked ~ option {
     color: transparent;
  }
  > option:hover:before, option:hover ~ option:before, option:checked:before, option:checked ~ option:before {
     content: "★";
     position: absolute;
     color: gold;
     text-shadow: 2px 2px 1px #000;
  }
  > option:hover, option:checked, option:active, option:focus {
    box-shadow: 0 0 10px 100px #000 inset;
  }
  `;
const Container = styled.div `
  clear: both;
`;
const Caption = styled.div `
  font-size: 1.2em;
`;
const RateValue = styled.div `
  float: left;
  padding:20px 10px;
`;

1 个答案:

答案 0 :(得分:0)

您必须在select选项上调用refresh方法来更新其可视样式。

希望这会奏效。