nav-frontend-skjema
Advanced tools
Comparing version 3.0.3 to 3.0.4
@@ -42,3 +42,3 @@ import * as PT from 'prop-types'; | ||
tellerTekst?: (antallTegn: number, maxLength: number) => React.ReactNode; | ||
textareaRef?: () => any; | ||
textareaRef?: (textarea: HTMLTextAreaElement | null) => any; | ||
} | ||
@@ -51,2 +51,6 @@ /** | ||
private tekstomrade; | ||
private textareaId; | ||
private maxTegnId?; | ||
private descriptionId?; | ||
private describedbyId; | ||
static propTypes: { | ||
@@ -111,3 +115,2 @@ /** | ||
updateHeight(): void; | ||
renderTextareaElement(textareaRef: any, textareaClass: any, textareaId: any, feilmelding: any, feilmeldingId: any, descriptionId: any, tellerId: any, name: any, onChange: any, other: any): JSX.Element; | ||
render(): JSX.Element; | ||
@@ -114,0 +117,0 @@ } |
@@ -41,2 +41,10 @@ "use strict"; | ||
_this.mirror = null; | ||
_this.tekstomrade = null; | ||
_this.textareaId = _this.props.id || nav_frontend_js_utils_1.guid(); | ||
_this.maxTegnId = _this.props.maxLength ? nav_frontend_js_utils_1.guid() : undefined; | ||
_this.descriptionId = _this.props.description ? nav_frontend_js_utils_1.guid() : undefined; | ||
_this.describedbyId = [_this.descriptionId, _this.maxTegnId].filter(function (id) { | ||
return !!id; | ||
}).join(' '); | ||
nav_frontend_js_utils_1.autobind(_this); | ||
@@ -67,21 +75,6 @@ return _this; | ||
} | ||
// tslint:disable-next-line max-line-length | ||
}, { | ||
key: "renderTextareaElement", | ||
value: function renderTextareaElement(textareaRef, textareaClass, textareaId, feilmelding, feilmeldingId, descriptionId, tellerId, name, onChange, other) { | ||
var _this2 = this; | ||
var describedBy = [descriptionId, tellerId].filter(function (id) { | ||
return !!id; | ||
}).join(' '); | ||
return React.createElement("textarea", Object.assign({ ref: function ref(textarea) { | ||
_this2.tekstomrade = textarea; | ||
if (textareaRef !== undefined) textareaRef(textarea); | ||
}, onChange: onChange, className: inputCls(textareaClass, feilmelding), type: "text", id: textareaId, name: name, style: { height: '30px' }, "aria-invalid": !!feilmelding, "aria-errormessage": feilmelding ? feilmeldingId : undefined, "aria-describedby": describedBy }, other)); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var _this3 = this; | ||
var _this2 = this; | ||
@@ -101,3 +94,2 @@ var _props = this.props, | ||
var textareaId = id || nav_frontend_js_utils_1.guid(); | ||
var antallTegn = other.value.length; | ||
@@ -107,7 +99,7 @@ return React.createElement(_1.SkjemaGruppeFeilContext.Consumer, null, function (context) { | ||
var feilmeldingId = context.feilmeldingId || nav_frontend_js_utils_1.guid(); | ||
var descriptionId = description ? nav_frontend_js_utils_1.guid() : undefined; | ||
var tellerId = nav_frontend_js_utils_1.guid(); | ||
var textareaEl = _this3.renderTextareaElement(textareaRef, textareaClass, textareaId, feilmelding, feilmeldingId, descriptionId, tellerId, name, onChange, other); | ||
return React.createElement("div", { className: "skjemaelement textarea__container" }, label && React.createElement(_1.Label, { htmlFor: textareaId }, label), description && React.createElement("div", { className: "skjemaelement__description", id: descriptionId }, description), React.createElement("div", { className: "textarea--medMeta__wrapper" }, React.createElement(nav_frontend_js_utils_1.EventThrottler, { event: "resize", callback: _this3.updateHeight, delay: 100 }, textareaEl), !!maxLength && React.createElement(Teller, { id: tellerId, antallTegn: antallTegn, maxLength: maxLength, tellerTekst: tellerTekst })), !!!context.feil && !!feil && React.createElement(skjemaelement_feilmelding_1.default, { id: feilmeldingId }, typeof feilmelding !== 'boolean' && feilmelding), React.createElement("div", { className: "textareamirror", ref: function ref(mirror) { | ||
_this3.mirror = mirror; | ||
return React.createElement("div", { className: "skjemaelement textarea__container" }, label && React.createElement(_1.Label, { htmlFor: _this2.textareaId }, label), description && React.createElement("div", { className: "skjemaelement__description", id: _this2.descriptionId }, description), React.createElement("div", { className: "textarea--medMeta__wrapper" }, _this2.props.maxLength && React.createElement("span", { id: _this2.maxTegnId, className: "sr-only" }, "Tekstomr\xE5de med plass til ", _this2.props.maxLength, " tegn."), React.createElement(nav_frontend_js_utils_1.EventThrottler, { event: "resize", callback: _this2.updateHeight, delay: 100 }, React.createElement("textarea", Object.assign({ ref: function ref(textarea) { | ||
_this2.tekstomrade = textarea; | ||
if (textareaRef !== undefined) textareaRef(textarea); | ||
}, onChange: onChange, className: inputCls(textareaClass, feilmelding), id: _this2.textareaId, name: name, style: { height: '30px' }, "aria-invalid": !!feilmelding, "aria-errormessage": feilmelding ? feilmeldingId : undefined, "aria-describedby": _this2.describedbyId }, other))), React.createElement(Teller, { antallTegn: antallTegn, maxLength: maxLength, tellerTekst: tellerTekst })), !!!context.feil && !!feil && React.createElement(skjemaelement_feilmelding_1.default, { id: feilmeldingId }, typeof feilmelding !== 'boolean' && feilmelding), React.createElement("div", { className: "textareamirror", ref: function ref(mirror) { | ||
_this2.mirror = mirror; | ||
}, "aria-hidden": "true" })); | ||
@@ -177,3 +169,6 @@ }); | ||
var Teller = function Teller(props) { | ||
return React.createElement("p", { id: props.id, className: "textarea--medMeta__teller" }, props.tellerTekst(props.antallTegn, props.maxLength)); | ||
if (props.maxLength <= 0) { | ||
return null; | ||
} | ||
return React.createElement("p", { className: "textarea--medMeta__teller" }, props.tellerTekst(props.antallTegn, props.maxLength)); | ||
}; | ||
@@ -180,0 +175,0 @@ function defaultTellerTekst(antallTegn, maxLength) { |
{ | ||
"name": "nav-frontend-skjema", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "types": "lib/index.d.ts", |
Sorry, the diff of this file is not supported yet
360662
3562