Re-add feature where readonly URL widget with label uses the label as link text

This commit is contained in:
nathan 2023-02-13 13:28:48 -07:00
parent fdd2d50fce
commit e2cbbe9358
2 changed files with 22 additions and 11 deletions

View File

@ -8,10 +8,8 @@
*/
/* eslint-disable import/no-extraneous-dependencies */
import {IsEmail} from "../Validators/IsEmail";
import {Et2Description} from "../Et2Description/Et2Description";
import {Et2UrlEmail} from "./Et2UrlEmail";
import {css} from "@lion/core";
import {css, TemplateResult} from "@lion/core";
import {Et2Url} from "./Et2Url";
/**
@ -37,7 +35,7 @@ export class Et2UrlReadonly extends Et2Description
{
attrs.onclick = () =>
{
if (this.value)
if(this.value)
{
Et2Url.action(this.value);
}
@ -45,6 +43,22 @@ export class Et2UrlReadonly extends Et2Description
}
super.transformAttributes(attrs);
}
/**
* Override parent render so we can have the special case where label is used as link text
*
* @returns {TemplateResult<1>}
* @protected
*/
protected render() : TemplateResult
{
if(this.label && !this.href && this.value)
{
// We have label & value, use label as link text
return this.wrapLink(this.value, this.label);
}
return super.render();
}
}
// @ts-ignore TypeScript is not recognizing that this is a LitElement
customElements.define("et2-url_ro", Et2UrlReadonly);

View File

@ -151,20 +151,17 @@ const Et2WidgetMixin = <T extends Constructor>(superClass : T) =>
*/
statustext: {
type: String,
reflect: true,
translate: true
reflect: true
},
/**
* The label of the widget
* This is usually displayed in some way. It's also important for accessability.
* This is defined in the parent somewhere, and re-defining it causes labels to disappear
*
label: {
type: String,
translate: true
},
*/
label: {
type: String
},
onclick: {
type: Function