Skip to content

Commit 38375ea

Browse files
authored
fix(ui): show inherited nodes in the shared disclosure (#1350)
* fix(ui): show inherited nodes in the shared disclosure The inherited section drew its own button, chevron and aria-expanded state. It now uses MdDisclosure, so the browser owns the open state. The warning lines keep role=alert. Signed-off-by: TheMeinerLP <github@themeinerlp.dev> * test(ui): assert the native semantics of the disclosure Cover the details element, the open attribute following the prop, no aria-expanded and a hidden body while collapsed. Signed-off-by: TheMeinerLP <github@themeinerlp.dev> --------- Signed-off-by: TheMeinerLP <github@themeinerlp.dev>
1 parent 58308a0 commit 38375ea

4 files changed

Lines changed: 95 additions & 100 deletions

File tree

‎reposilite-frontend/src/components/access/nodes/NodeEditor.test.ts‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -722,15 +722,15 @@ describe('NodeEditor', () => {
722722
})
723723

724724
describe('inherited nodes', () => {
725-
const toggle = () => wrapper.find('[data-test="inherited-toggle"]')
726-
const region = () => wrapper.find(`[id="${toggle().attributes('aria-controls')}"]`)
725+
const details = () => wrapper.find<HTMLDetailsElement>('[data-test="inherited-section"] details')
726+
const summary = () => wrapper.find('[data-test="inherited-section"] summary')
727727

728-
it('draws the toggle with a 40 pixel body and a 48 pixel touch target', () => {
728+
it('is a shared disclosure, so the browser owns the open state', () => {
729729
mountEditor({ inherited: INHERITED() })
730730

731-
expect(toggle().classes(), 'a 40 pixel body').toContain('min-h-10')
732-
expect(toggle().classes(), 'a 48 pixel hit area').toContain('md-touch-target')
733-
expect(toggle().classes(), 'the old 48 pixel body is gone').not.toContain('min-h-12')
731+
expect(details().exists(), 'a native details element').toBe(true)
732+
expect(summary().text()).toContain('Inherited from teams (2)')
733+
expect(summary().attributes('aria-expanded'), 'the semantics are native').toBeUndefined()
734734
})
735735

736736
it('shows the source team and the distance of a node from a parent team', () => {
@@ -782,26 +782,24 @@ describe('NodeEditor', () => {
782782
it('is open to start with', () => {
783783
mountEditor({ inherited: INHERITED() })
784784

785-
expect(toggle().attributes('aria-expanded')).toBe('true')
786-
expect(region().isVisible()).toBe(true)
785+
expect(details().element.open).toBe(true)
787786
})
788787

789-
it('collapses with its button and reports it through aria-expanded', async () => {
788+
it('collapses with its summary', async () => {
790789
mountEditor({ inherited: INHERITED() })
791790

792-
await toggle().trigger('click')
791+
await summary().trigger('click')
793792

794-
expect(toggle().attributes('aria-expanded')).toBe('false')
795-
expect(region().isVisible()).toBe(false)
793+
expect(wrapper.find('[data-test="inherited-section"] details .expand-rows').isVisible(), 'the body collapses').toBe(false)
796794
})
797795

798796
it('opens again with a second press', async () => {
799797
mountEditor({ inherited: INHERITED() })
800-
await toggle().trigger('click')
798+
await summary().trigger('click')
801799

802-
await toggle().trigger('click')
800+
await summary().trigger('click')
803801

804-
expect(region().isVisible()).toBe(true)
802+
expect(details().element.open).toBe(true)
805803
})
806804

807805
it('is absent when nothing is inherited', () => {

‎reposilite-frontend/src/components/access/nodes/NodeInheritedSection.vue‎

Lines changed: 58 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
-->
1616

1717
<script setup lang="ts">
18-
import { ref, useId, type PropType } from 'vue'
18+
import { ref, type PropType } from 'vue'
1919
import MdBadge from '../../md/MdBadge.vue'
20+
import MdDisclosure from '../../md/MdDisclosure.vue'
2021
import MdList from '../../md/MdList.vue'
2122
import MdListItem from '../../md/MdListItem.vue'
2223
import type { InheritedEntry } from './inheritedNodes'
2324
import { inheritedSourceLabel, isOverridden } from './nodeList'
2425
import type { NodeEntry } from './permissionNodesApi'
2526
2627
/*
27-
* The nodes a subject gets from teams, read only. The section is open to start with and a button
28-
* collapses it. A node that the subject also holds directly (same node text) is still listed and
28+
* The nodes a subject gets from teams, read only. The section is a disclosure, open to start with. A node that the subject also holds directly (same node text) is still listed and
2929
* is marked as overridden, because the direct node decides first.
3030
*/
3131
defineProps({
@@ -47,7 +47,6 @@ defineProps({
4747
})
4848
4949
const open = ref(true)
50-
const regionId = `inherited-${useId()}`
5150
</script>
5251

5352
<template>
@@ -56,83 +55,62 @@ const regionId = `inherited-${useId()}`
5655
data-test="inherited-section"
5756
data-ingot-component="node-inherited-section"
5857
>
59-
<button
60-
type="button"
61-
class="md-state-layer md-focus-ring md-touch-target relative inline-flex min-h-10 w-fit items-center gap-2 rounded-corner-medium px-3 md-title-small text-on-surface"
62-
:aria-expanded="open ? 'true' : 'false'"
63-
:aria-controls="regionId"
64-
data-test="inherited-toggle"
65-
@click="open = !open"
66-
>
67-
<svg
68-
class="size-6 shrink-0 transition-transform duration-(--md-sys-motion-duration-short3)"
69-
:class="open ? '' : '-rotate-90'"
70-
viewBox="0 -960 960 960"
71-
aria-hidden="true"
72-
focusable="false"
73-
>
74-
<path
75-
fill="currentColor"
76-
d="M480-345 240-585l56-56 184 184 184-184 56 56-240 240Z"
77-
/>
78-
</svg>
79-
Inherited from teams ({{ inherited.length }})
80-
</button>
81-
<div
82-
v-show="open"
83-
:id="regionId"
84-
class="flex flex-col gap-2"
85-
>
86-
<p class="md-body-medium text-on-surface-variant">
87-
These nodes come from teams and cannot be changed here. A direct node that matches the same permission decides first.
88-
</p>
89-
<p
90-
v-for="warning in warnings"
91-
:key="warning"
92-
role="alert"
93-
class="md-body-medium text-warning"
94-
data-test="inherited-warning"
95-
>
96-
{{ warning }}
97-
</p>
98-
<div
99-
v-if="inherited.length > 0"
100-
class="rounded-corner-medium border border-outline-variant"
101-
>
102-
<MdList divided>
103-
<MdListItem
104-
v-for="entry in inherited"
105-
:key="`${entry.source}:${entry.subject}:${entry.node}`"
106-
data-test="inherited-row"
107-
:data-node="entry.node"
108-
>
109-
<code class="md-code-medium text-on-surface break-all"><template
110-
v-for="(part, index) in entry.node.split('.')"
111-
:key="index"
112-
>{{ part }}<template v-if="index < entry.node.split('.').length - 1">.<wbr></template></template></code>
113-
<p
114-
class="md-body-small text-on-surface-variant"
115-
data-test="inherited-source"
58+
<MdDisclosure v-model:open="open">
59+
<template #summary>
60+
Inherited from teams ({{ inherited.length }})
61+
</template>
62+
<div class="flex flex-col gap-2">
63+
<p class="md-body-medium text-on-surface-variant">
64+
These nodes come from teams and cannot be changed here. A direct node that matches the same permission decides first.
65+
</p>
66+
<p
67+
v-for="warning in warnings"
68+
:key="warning"
69+
role="alert"
70+
class="md-body-medium text-warning"
71+
data-test="inherited-warning"
72+
>
73+
{{ warning }}
74+
</p>
75+
<div
76+
v-if="inherited.length > 0"
77+
class="rounded-corner-medium border border-outline-variant"
78+
>
79+
<MdList divided>
80+
<MdListItem
81+
v-for="entry in inherited"
82+
:key="`${entry.source}:${entry.subject}:${entry.node}`"
83+
data-test="inherited-row"
84+
:data-node="entry.node"
11685
>
117-
{{ inheritedSourceLabel(entry) }}
118-
</p>
119-
<MdBadge
120-
v-if="isOverridden(entry, direct)"
121-
class="mt-1"
122-
data-test="inherited-overridden"
123-
>
124-
Overridden by a direct node
125-
</MdBadge>
126-
<template #trailing>
127-
<span
128-
class="md-label-large"
129-
:class="entry.allowed ? 'text-on-surface' : 'text-error'"
130-
data-test="inherited-state"
131-
>{{ entry.allowed ? 'Allowed' : 'Denied' }}</span>
132-
</template>
133-
</MdListItem>
134-
</MdList>
86+
<code class="md-code-medium text-on-surface break-all"><template
87+
v-for="(part, index) in entry.node.split('.')"
88+
:key="index"
89+
>{{ part }}<template v-if="index < entry.node.split('.').length - 1">.<wbr></template></template></code>
90+
<p
91+
class="md-body-small text-on-surface-variant"
92+
data-test="inherited-source"
93+
>
94+
{{ inheritedSourceLabel(entry) }}
95+
</p>
96+
<MdBadge
97+
v-if="isOverridden(entry, direct)"
98+
class="mt-1"
99+
data-test="inherited-overridden"
100+
>
101+
Overridden by a direct node
102+
</MdBadge>
103+
<template #trailing>
104+
<span
105+
class="md-label-large"
106+
:class="entry.allowed ? 'text-on-surface' : 'text-error'"
107+
data-test="inherited-state"
108+
>{{ entry.allowed ? 'Allowed' : 'Denied' }}</span>
109+
</template>
110+
</MdListItem>
111+
</MdList>
112+
</div>
135113
</div>
136-
</div>
114+
</MdDisclosure>
137115
</section>
138116
</template>

‎reposilite-frontend/src/components/md/MdDisclosure.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,30 @@ describe('MdDisclosure content', () => {
7676
})
7777
})
7878

79+
describe('MdDisclosure native semantics', () => {
80+
it('is a native details element and sets no aria-expanded, because the semantics are native', () => {
81+
const wrapper = mountDisclosure()
82+
83+
expect(wrapper.element instanceof HTMLDetailsElement, 'the root is a native details').toBe(true)
84+
expect(wrapper.find('[aria-expanded]').exists(), 'nothing duplicates the native state').toBe(false)
85+
})
86+
87+
it('toggles the open attribute of the details element with the open prop', async () => {
88+
const wrapper = mountDisclosure()
89+
expect(wrapper.attributes('open'), 'closed has no open attribute').toBeUndefined()
90+
91+
await wrapper.setProps({ open: true })
92+
93+
expect(wrapper.attributes('open'), 'open sets the attribute').toBeDefined()
94+
})
95+
96+
it('hides the content while collapsed', () => {
97+
const wrapper = mountDisclosure()
98+
99+
expect(wrapper.find('details > div').isVisible(), 'the body is not visible while collapsed').toBe(false)
100+
})
101+
})
102+
79103
describe('MdDisclosure value', () => {
80104
it('emits update:open with true when the browser opens the body', async () => {
81105
const wrapper = mountDisclosure({ open: false })

‎reposilite-frontend/src/style-gate/baseline/inline-svg.json‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
"match": "<svg",
1515
"count": 1
1616
},
17-
{
18-
"file": "src/components/access/nodes/NodeInheritedSection.vue",
19-
"match": "<svg",
20-
"count": 1
21-
},
2217
{
2318
"file": "src/components/access/nodes/NodeRow.vue",
2419
"match": "<svg",

0 commit comments

Comments
 (0)