All files / src/components/fields/date DateField.ts

41.67% Statements 5/12
0% Branches 0/2
0% Functions 0/5
41.67% Lines 5/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 361x 1x 1x                   1x                                             1x
import Field from "../Field";
import defineCustomElement from "../../../custom-element/helpers/defineCustomElement";
import html from "../../../renderer/html";
import { NodePatchingData } from "../../../renderer/NodePatcher";
 
function formatDate(value: string) {
 
    const i = value.indexOf('T');
 
    return value.substring(0, i); // Extract the date part only
}
 
export default class DateField extends Field {
 
    render(): NodePatchingData {
 
        const {
            name,
            value,
            //required,
            disabled
        } = this;
 
        return html`<input
            type="date"
            name=${name}
            value=${value !== undefined ? formatDate(value) : undefined}
            onInput=${event => this.handleInput(event)}
            onChange=${event => this.handleChange(event)}
            onBlur=${event => this.handleBlur(event)}
            disabled=${disabled}
        />`;
    }
}
 
defineCustomElement('gcl-date-field', DateField);