0

如何在 KendoReact DatePicker 中放置浮动标签?

https://www.telerik.com/kendo-react-ui/components/dropdowns/floating-labels/

4

1 回答 1

1

我建议使用自定义占位符条件渲染。Kendo 使用类来获取浮动标签的样式,嵌套跨度将实现这一点。我已经添加了我尝试过的代码片段,但由于我不熟悉 React,我无法让条件渲染工作。

import * as React from 'react';
import * as ReactDOM from 'react-dom';

import { dataProducts, dataCategories, dataOrders } from './data';
import { DateInput, Calendar, DatePicker, TimePicker, MultiViewCalendar, DateRangePicker } from '@progress/kendo-react-dateinputs';
class App extends React.Component {
    render() {
      const isFocused = false;
        return (
            <div>
                <div>
                    <p>DatePicker</p>                    
                    {isFocused
                     ?  <span class="k-textbox-container k-state-focused k-state-empty"><span class="k-label">Select Order Date</span></span>
                     : null}

                    <div onFocus = {this.onFocusDatePickerInput} onBlur = {this.onBlurDatePickerInput} >
                        <DatePicker format="MM dd yyyy" formatPlaceholder={{ year: 'Date', month: 'Select', day: 'Order' }} 
                                    onChange={this.changeDate} />
                    </div>
                </div>
            </div>
        );
    }

    changeDate = (event) => {
      console.log(event.value)
       if(event.value){
        this.format= "MM/dd/yyyy";
        this.setState({ value: event.value });
        }
    }

    onFocusDatePickerInput = () => 
    {
      this.isFocused = true;
      console.log(this.isFocused)
    }

    onBlurDatePickerInput = () => 
    {
      this.isFocused = false;
      console.log(this.isFocused)
    }

}

ReactDOM.render(
    <App />,
    document.querySelector('my-app')
);
于 2019-04-03T09:04:28.840 回答