@policystudio/policy-studio-ui-vue 1.2.0-access.75 → 1.2.0-access.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@policystudio/policy-studio-ui-vue",
3
- "version": "1.2.0-access.75",
3
+ "version": "1.2.0-access.77",
4
4
  "description": "Policy Studio UI",
5
5
  "author": "Policy Studio Team",
6
6
  "scripts": {
@@ -12,6 +12,8 @@
12
12
  <div
13
13
  @click="toggle"
14
14
  @keydown.enter.stop="toggle"
15
+ @focusin="onHeaderFocusIn"
16
+ @focusout="onHeaderFocusOut"
15
17
  class="psui-el-accordion-item-header-wrapper"
16
18
  tabindex="0"
17
19
  v-if="!hasCustomHeader"
@@ -55,8 +57,11 @@ import { useCollapseAnimation } from '../../../dist/composables/useCollapseAnima
55
57
  import { ref, computed, getCurrentInstance } from 'vue'
56
58
 
57
59
  const { beforeEnter, enter, afterEnter, beforeLeave, leave } = useCollapseAnimation()
60
+
61
+ const emit = defineEmits(['header-focusin', 'header-focusout'])
62
+
58
63
  defineExpose({
59
- toggle: () => toggle()
64
+ toggle: () => _toggle()
60
65
  })
61
66
 
62
67
  const localOpened = ref(null)
@@ -97,6 +102,14 @@ const props = defineProps({
97
102
  type: Boolean,
98
103
  default: false,
99
104
  },
105
+ /**
106
+ * A callback called before toggling. If it returns false, the toggle is prevented.
107
+ * Only affects user-initiated interactions (click/Enter), not programmatic calls.
108
+ */
109
+ beforeToggle: {
110
+ type: Function,
111
+ default: null,
112
+ },
100
113
  })
101
114
 
102
115
  const isOpen = computed(() => {
@@ -127,7 +140,7 @@ const getIcon = computed(() => {
127
140
  return `${props.icon}`
128
141
  })
129
142
 
130
- const toggle = () => {
143
+ const _toggle = () => {
131
144
  if (localOpened.value === null) {
132
145
  localOpened.value = !props.opened
133
146
  } else {
@@ -135,6 +148,20 @@ const toggle = () => {
135
148
  }
136
149
  }
137
150
 
151
+ const toggle = () => {
152
+ if (props.disabled) return
153
+ if (props.beforeToggle && props.beforeToggle() === false) return
154
+ _toggle()
155
+ }
156
+
157
+ const onHeaderFocusIn = (e) => emit('header-focusin', e)
158
+
159
+ const onHeaderFocusOut = (e) => {
160
+ if (!e.currentTarget.contains(e.relatedTarget)) {
161
+ emit('header-focusout', e)
162
+ }
163
+ }
164
+
138
165
  </script>
139
166
 
140
167
  <style>
@@ -3,6 +3,7 @@
3
3
  class="psui-el-switch"
4
4
  :class="[getComponentClass, { disabled: disabled }]"
5
5
  @click="change()"
6
+ @keydown.enter.stop="change()"
6
7
  tabindex="0"
7
8
  >
8
9
  <span
@@ -4,6 +4,7 @@
4
4
  ref="PSDropdownTrigger"
5
5
  @click="toggle"
6
6
  @keydown.enter.stop.prevent="toggle"
7
+ @keydown.space.stop.prevent="toggle"
7
8
  >
8
9
  <slot
9
10
  v-if="hasDropdownTrigger"
@@ -159,9 +160,10 @@ const moveFocus = (offset) => {
159
160
  focusable[nextIndex].focus()
160
161
  }
161
162
 
162
- const open = () => {
163
+ const open = async () => {
163
164
  show.value = true
164
165
  emit('open')
166
+ await focusFirstElement()
165
167
  }
166
168
 
167
169
  const close = (event) => {
@@ -176,14 +178,12 @@ const toggle = async (event) => {
176
178
 
177
179
  if (event) event.stopPropagation()
178
180
 
179
- show.value = !show.value
180
-
181
- if (show.value) {
182
- await focusFirstElement()
181
+ if (!show.value) {
182
+ await open()
183
183
  } else {
184
- emit('close')
184
+ close()
185
185
  }
186
186
  }
187
187
 
188
- defineExpose({ open, close })
188
+ defineExpose({ open, close, toggle })
189
189
  </script>