Skip to content

Commit d37861c

Browse files
madsrasmusseniOvergaard
authored andcommitted
feat: implement readonly mode for uui-ref-node
1 parent 33f171e commit d37861c

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

packages/uui-ref-node/lib/uui-ref-node.element.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,18 @@ export class UUIRefNodeElement extends UUIRefElement {
8585

8686
#renderContent() {
8787
return html`
88-
<span id="icon">
89-
<slot name="icon" @slotchange=${this.#onSlotIconChange}></slot>
90-
${this._iconSlotHasContent === false ? this.#renderFallbackIcon() : ''}
88+
<span id="content">
89+
<span id="icon">
90+
<slot name="icon" @slotchange=${this.#onSlotIconChange}></slot>
91+
${this._iconSlotHasContent === false
92+
? this.#renderFallbackIcon()
93+
: ''}
94+
</span>
95+
<div id="info">
96+
<div id="name">${this.name}</div>
97+
${this.renderDetail()}
98+
</div>
9199
</span>
92-
<div id="info">
93-
<div id="name">${this.name}</div>
94-
${this.renderDetail()}
95-
</div>
96100
`;
97101
}
98102

@@ -125,7 +129,7 @@ export class UUIRefNodeElement extends UUIRefElement {
125129

126130
public render() {
127131
return html`
128-
${this.href ? this.#renderLink() : this.#renderButton()}
132+
${this.#renderSomething()}
129133
<!-- Select border must be right after #open-part -->
130134
<div id="select-border"></div>
131135
@@ -135,6 +139,14 @@ export class UUIRefNodeElement extends UUIRefElement {
135139
`;
136140
}
137141

142+
#renderSomething() {
143+
if (this.readonly) {
144+
return html`${this.#renderContent()}`;
145+
} else {
146+
return this.href ? this.#renderLink() : this.#renderButton();
147+
}
148+
}
149+
138150
static styles = [
139151
...UUIRefElement.styles,
140152
css`
@@ -143,15 +155,17 @@ export class UUIRefNodeElement extends UUIRefElement {
143155
padding: calc(var(--uui-size-2) + 1px);
144156
}
145157
146-
#open-part {
147-
text-decoration: none;
148-
color: inherit;
158+
#content {
149159
align-self: stretch;
150160
line-height: normal;
151-
152161
display: flex;
153162
position: relative;
154163
align-items: center;
164+
}
165+
166+
#open-part {
167+
color: inherit;
168+
text-decoration: none;
155169
cursor: pointer;
156170
}
157171

packages/uui-ref/lib/uui-ref.element.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ export class UUIRefElement extends SelectOnlyMixin(
3131
@property({ type: Boolean, reflect: true })
3232
disabled = false;
3333

34+
/**
35+
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
36+
* @type {boolean}
37+
* @attr
38+
* @default false
39+
*/
40+
@property({ type: Boolean, reflect: true })
41+
readonly = false;
42+
3443
/**
3544
* Set to true to display error state
3645
* @type {boolean}

0 commit comments

Comments
 (0)