Skip to content

Commit 6a15ba1

Browse files
Joren BroekemadaKmoR
authored andcommitted
fix(select-rich): make readonly work
1 parent c0616b9 commit 6a15ba1

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

packages/select-rich/src/LionSelectRich.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ export class LionSelectRich extends OverlayMixin(
511511

512512
__setupInvokerNodeEventListener() {
513513
this.__invokerOnClick = () => {
514-
if (!this.disabled) {
514+
if (!this.disabled && !this.readOnly) {
515515
this._overlayCtrl.toggle();
516516
}
517517
};

packages/select-rich/stories/index.stories.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ storiesOf('Forms|Select Rich', module)
5757
</div>
5858
`,
5959
)
60+
.add(
61+
'Read-only prefilled',
62+
() => html`
63+
<style>
64+
${selectRichDemoStyle}
65+
</style>
66+
<div class="demo-area">
67+
<lion-select-rich label="Read-only select" readonly name="color">
68+
<lion-options slot="input">
69+
<lion-option .modelValue=${{ value: 'red', checked: false }}>Red</lion-option>
70+
<lion-option .modelValue=${{ value: 'hotpink', checked: true }}>Hotpink</lion-option>
71+
<lion-option .modelValue=${{ value: 'teal', checked: false }}>Teal</lion-option>
72+
</lion-options>
73+
</lion-select-rich>
74+
</div>
75+
`,
76+
)
6077
.add(
6178
'Disabled',
6279
() => html`

packages/select-rich/test/lion-select-rich.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,34 @@ describe('lion-select-rich', () => {
159159
expect(options[1].active).to.be.true;
160160
expect(options[1].checked).to.be.true;
161161
});
162+
163+
it('stays closed on click if it disabled or readonly', async () => {
164+
const elReadOnly = await fixture(html`
165+
<lion-select-rich readonly>
166+
<lion-options slot="input">
167+
<lion-option .choiceValue=${10}>Item 1</lion-option>
168+
<lion-option .choiceValue=${20} checked>Item 2</lion-option>
169+
</lion-options>
170+
</lion-select-rich>
171+
`);
172+
173+
const elDisabled = await fixture(html`
174+
<lion-select-rich disabled>
175+
<lion-options slot="input">
176+
<lion-option .choiceValue=${10}>Item 1</lion-option>
177+
<lion-option .choiceValue=${20} checked>Item 2</lion-option>
178+
</lion-options>
179+
</lion-select-rich>
180+
`);
181+
182+
elReadOnly._invokerNode.click();
183+
await elReadOnly.updateComplete;
184+
expect(elReadOnly.opened).to.be.false;
185+
186+
elDisabled._invokerNode.click();
187+
await elDisabled.updateComplete;
188+
expect(elDisabled.opened).to.be.false;
189+
});
162190
});
163191

164192
describe('interaction-mode', () => {

0 commit comments

Comments
 (0)