Skip to content

Commit 70f414d

Browse files
bug - fix menu dropdown not opening after delete (#22752)
* fix menu dropdonw not opening after delete * add changelog and tests * Update changelog file
1 parent eadffc4 commit 70f414d

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

.changelog/22752.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
ui: fixes the issue where when doing deletes of multiple tokens or policies, the three dots on the right hand side stops responding after the first delete.
3+
```

ui/packages/consul-ui/app/components/list-collection/index.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<YieldSlot @name="details"><div class="detail">{{yield cell.item cell.index}}</div></YieldSlot>
3434
<YieldSlot @name="actions"
3535
@params={{
36-
block-params (component 'more-popover-menu' expanded=(if (eq checked cell.index) true false) onchange=(action "change" cell.index))
36+
block-params (component 'more-popover-menu' expanded=(if (eq checked cell.item.uid) true false) onchange=(action "change" cell.item.uid))
3737
}}
3838
>
3939
<div class="actions">
@@ -51,13 +51,13 @@
5151
<li
5252
data-test-list-row
5353
onclick={{action 'click'}}
54-
class={{if (not linkable) 'linkable' (if (is linkable item=cell.item) 'linkable')}}
54+
class={{if (not linkable) 'linkable' (if (is linkable item=item) 'linkable')}}
5555
>
5656
<YieldSlot @name="header"><div class="header">{{yield item index}}</div></YieldSlot>
5757
<YieldSlot @name="details"><div class="detail">{{yield item index}}</div></YieldSlot>
5858
<YieldSlot @name="actions"
5959
@params={{
60-
block-params (component 'more-popover-menu' onchange=(action "change" index))
60+
block-params (component 'more-popover-menu' onchange=(action "change" item.uid))
6161
}}
6262
>
6363
<div class="actions">

ui/packages/consul-ui/app/components/list-collection/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export default Component.extend(Slotted, {
4040
const o = this;
4141
this['cell-layout'].formatItemStyle = function (itemIndex) {
4242
let style = formatItemStyle.apply(this, arguments);
43-
if (o.checked === itemIndex) {
43+
const items = get(o, 'items');
44+
if (items && items[itemIndex] && o.checked === items[itemIndex].uid) {
4445
style = `${style};z-index: 1`;
4546
}
4647
return style;
@@ -75,7 +76,7 @@ export default Component.extend(Slotted, {
7576
},
7677
change: function (index, e = {}) {
7778
if (e.target.checked && index !== this.checked) {
78-
set(this, 'checked', parseInt(index));
79+
set(this, 'checked', index);
7980
this.$row = this.dom.closest('li', e.target);
8081
this.$row.style.zIndex = 1;
8182

ui/packages/consul-ui/tests/integration/components/list-collection-test.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { module, test } from 'qunit';
77
import { setupRenderingTest } from 'ember-qunit';
8-
import { render } from '@ember/test-helpers';
8+
import { render, triggerEvent } from '@ember/test-helpers';
99
import hbs from 'htmlbars-inline-precompile';
1010

1111
module('Integration | Component | list collection', function (hooks) {
@@ -26,4 +26,48 @@ module('Integration | Component | list collection', function (hooks) {
2626

2727
assert.dom('*').hasText('');
2828
});
29+
30+
test('it manages checked state and z-index on change', async function (assert) {
31+
this.set('items', [
32+
{ id: 1, name: 'Item 1' },
33+
{ id: 2, name: 'Item 2' },
34+
]);
35+
36+
// Add a footer for collision detection
37+
const footer = document.createElement('footer');
38+
footer.setAttribute('role', 'contentinfo');
39+
footer.style.position = 'fixed';
40+
footer.style.bottom = '0';
41+
footer.style.height = '50px';
42+
document.body.appendChild(footer);
43+
44+
await render(hbs`
45+
<ListCollection @items={{this.items}} as |item index Actions|>
46+
<BlockSlot @name="header">{{item.name}}</BlockSlot>
47+
<BlockSlot @name="actions" as |Actions|>
48+
<Actions as |Action|>
49+
<Action>
50+
<BlockSlot @name="label">Action</BlockSlot>
51+
</Action>
52+
</Actions>
53+
</BlockSlot>
54+
</ListCollection>
55+
`);
56+
57+
const checkbox = this.element.querySelector('input[type="checkbox"]');
58+
const row = this.element.querySelector('[data-test-list-row]');
59+
60+
// Test checking - should set z-index and handle footer collision
61+
checkbox.checked = true;
62+
await triggerEvent(checkbox, 'change');
63+
assert.equal(row.style.zIndex, '1', 'Row should have z-index 1 when checked');
64+
65+
// Test unchecking - should clear z-index
66+
checkbox.checked = false;
67+
await triggerEvent(checkbox, 'change');
68+
assert.strictEqual(row.style.zIndex, '', 'Row z-index should be cleared when unchecked');
69+
70+
// Cleanup
71+
document.body.removeChild(footer);
72+
});
2973
});

0 commit comments

Comments
 (0)