| 1 |
<template> |
| 2 |
<ElSelect |
| 3 |
ref="elInputRef" |
| 4 |
v-bind="{ ...$attrs, ...$props }" |
| 5 |
v-model="model" |
| 6 |
:placeholder="props.placeholder" |
| 7 |
:disabled="props.disabled" |
| 8 |
:readonly="props.readonly" |
| 9 |
:multiple="props.multiple" |
| 10 |
:collapse-tags="props.multiple" |
| 11 |
:clearable="props.clearable && !props.readonly" |
| 12 |
:class="[ |
| 13 |
{ |
| 14 |
'is-clearable': props.clearable && !props.readonly, |
| 15 |
'is-filled': props.filled, |
| 16 |
'is-secondary': isSecondary, |
| 17 |
'is-error': props.error, |
| 18 |
'is-readonly': props.readonly, |
| 19 |
}, |
| 20 |
'ivyforms-form-item-select', |
| 21 |
]" |
| 22 |
:max-collapse-tags="props.maxTags" |
| 23 |
:aria-label="computedAriaLabel" |
| 24 |
:fit-input-width="props.fitInputWidth" |
| 25 |
> |
| 26 |
<template v-if="!!slots['prefix'] || iconStart" #prefix> |
| 27 |
<slot name="prefix"> |
| 28 |
<IvyIcon |
| 29 |
v-if="iconStart" |
| 30 |
:name="iconStart" |
| 31 |
:category="iconStartCategory" |
| 32 |
:type="iconStartType" |
| 33 |
class="ivyforms-input__icon-start" |
| 34 |
size="l" |
| 35 |
color="var(--map-base-dusk-symbol-2)" |
| 36 |
/> |
| 37 |
|
| 38 |
<!-- TODO Add the avatar component--> |
| 39 |
<IvyIcon v-if="props.avatar" class="ivyforms-input__avatar" name="user" size="l" /> |
| 40 |
<!-- <IvyAvatar--> |
| 41 |
<!-- v-if="props.avatar"--> |
| 42 |
<!-- class="ivyforms-input__avatar"--> |
| 43 |
<!-- />--> |
| 44 |
</slot> |
| 45 |
</template> |
| 46 |
<slot /> |
| 47 |
</ElSelect> |
| 48 |
</template> |
| 49 |
|
| 50 |
<script setup lang="ts"> |
| 51 |
import { useSlots, inject, computed, ref, onMounted, nextTick } from 'vue' |
| 52 |
import type { IconCategory } from '@/types/icons/icon-category' |
| 53 |
import type { IconType } from '@/types/icons/icon-type' |
| 54 |
import { useLabels } from '@/composables/useLabels' |
| 55 |
const { getLabel } = useLabels() |
| 56 |
|
| 57 |
interface Props { |
| 58 |
modelValue: string | string[] | null | undefined |
| 59 |
label?: string |
| 60 |
placeholder?: string |
| 61 |
iconStart?: string |
| 62 |
iconEnd?: string |
| 63 |
iconStartCategory?: IconCategory |
| 64 |
iconEndCategory?: IconCategory |
| 65 |
avatar?: string |
| 66 |
iconStartType?: IconType |
| 67 |
iconEndType?: IconType |
| 68 |
filled?: boolean |
| 69 |
prefix?: string |
| 70 |
suffix?: string |
| 71 |
clearable?: boolean |
| 72 |
disabled?: boolean |
| 73 |
readonly?: boolean |
| 74 |
multiple?: boolean |
| 75 |
maxTags?: number |
| 76 |
ariaLabel?: string |
| 77 |
error?: boolean |
| 78 |
fieldType?: string |
| 79 |
fitInputWidth?: boolean |
| 80 |
secondary?: boolean |
| 81 |
} |
| 82 |
|
| 83 |
const props = withDefaults(defineProps<Props>(), { |
| 84 |
placeholder: '', |
| 85 |
iconStartCategory: 'global', |
| 86 |
iconEndCategory: 'global', |
| 87 |
iconStartType: 'outline', |
| 88 |
iconEndType: 'outline', |
| 89 |
label: '', |
| 90 |
iconStart: '', |
| 91 |
iconEnd: '', |
| 92 |
avatar: '', |
| 93 |
prefix: '', |
| 94 |
suffix: '', |
| 95 |
maxTags: 3, |
| 96 |
ariaLabel: '', |
| 97 |
error: false, |
| 98 |
readonly: false, |
| 99 |
fieldType: '', |
| 100 |
fitInputWidth: true, |
| 101 |
secondary: false, |
| 102 |
}) |
| 103 |
|
| 104 |
const isSecondary = computed(() => props.secondary || inject('isSecondary', false)) |
| 105 |
|
| 106 |
const slots = useSlots() |
| 107 |
|
| 108 |
const emit = defineEmits(['update:modelValue']) |
| 109 |
|
| 110 |
const elInputRef = ref(null) |
| 111 |
|
| 112 |
const model = computed({ |
| 113 |
get: () => props.modelValue, |
| 114 |
set: (value) => { |
| 115 |
if (!props.readonly) { |
| 116 |
emit('update:modelValue', value) |
| 117 |
} |
| 118 |
}, |
| 119 |
}) |
| 120 |
|
| 121 |
const computedAriaLabel = computed(() => props.ariaLabel || getLabel('select')) |
| 122 |
|
| 123 |
// Add keyboard accessibility to select dropdown wrap element |
| 124 |
onMounted(() => { |
| 125 |
nextTick(() => { |
| 126 |
// Find all el-select-dropdown__wrap elements and make them focusable |
| 127 |
const dropdownWraps = document.querySelectorAll('.el-select-dropdown__wrap') |
| 128 |
dropdownWraps.forEach((wrap) => { |
| 129 |
const wrapElement = wrap as HTMLElement |
| 130 |
// Make dropdown wrap focusable with keyboard |
| 131 |
if (!wrapElement.hasAttribute('tabindex')) { |
| 132 |
wrapElement.setAttribute('tabindex', '0') |
| 133 |
} |
| 134 |
// Add ARIA role for better screen reader support |
| 135 |
if (!wrapElement.hasAttribute('role')) { |
| 136 |
wrapElement.setAttribute('role', 'region') |
| 137 |
wrapElement.setAttribute('aria-label', getLabel('select_options')) |
| 138 |
} |
| 139 |
}) |
| 140 |
}) |
| 141 |
}) |
| 142 |
</script> |
| 143 |
|
| 144 |
<style lang="scss"> |
| 145 |
.ivyforms-form-item-select { |
| 146 |
.el-select__wrapper { |
| 147 |
border: 1px solid var(--map-base-dusk-stroke--2); |
| 148 |
background: var(--map-base-dusk-o05); |
| 149 |
border-radius: var(--Radius-radius-md, 8px); |
| 150 |
display: flex; |
| 151 |
align-items: center; |
| 152 |
gap: var(--Spacing-sm, 8px); |
| 153 |
padding: var(--Spacing-sm, 8px) var(--Spacing-lg, 12px); |
| 154 |
height: 40px; |
| 155 |
box-shadow: none !important; |
| 156 |
|
| 157 |
&.is-disabled { |
| 158 |
background: var(--map-base-dusk-o05); |
| 159 |
} |
| 160 |
|
| 161 |
&:hover:not(.is-disabled), |
| 162 |
&.is-hovering:not(.is-focused):not(.is-disabled) { |
| 163 |
border: 1px solid var(--map-base-dusk-stroke-0); |
| 164 |
} |
| 165 |
|
| 166 |
&:focus, |
| 167 |
&:active, |
| 168 |
&.is-active, |
| 169 |
&.is-focused { |
| 170 |
border: 1px solid var(--map-base-brand-stroke-0) !important; |
| 171 |
|
| 172 |
.el-tag { |
| 173 |
background: var(--map-base-brand-o10); |
| 174 |
color: var(--map-base-brand-symbol-0); |
| 175 |
|
| 176 |
.el-tag__close svg { |
| 177 |
color: var(--map-base-brand-symbol-0); |
| 178 |
width: 14px; |
| 179 |
height: 14px; |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
&:hover:focus, |
| 185 |
&:hover.is-focused, |
| 186 |
&.is-hovering.is-focused { |
| 187 |
border: 1px solid var(--map-base-brand-stroke-0) !important; |
| 188 |
} |
| 189 |
|
| 190 |
.el-select__selection { |
| 191 |
padding: 0; |
| 192 |
font-size: 16px; |
| 193 |
font-weight: 400; |
| 194 |
line-height: 22px; |
| 195 |
color: var(--map-base-text-0); |
| 196 |
background-color: transparent; |
| 197 |
display: flex; |
| 198 |
align-items: center; |
| 199 |
gap: 4px; |
| 200 |
flex: 1 0 0; |
| 201 |
} |
| 202 |
|
| 203 |
.el-select__suffix .el-icon.el-select__caret.el-select__icon { |
| 204 |
background: url('../../../assets/icons/arrows/line/chevron-down.svg') no-repeat center; |
| 205 |
background-size: contain; |
| 206 |
width: 20px; |
| 207 |
height: 20px; |
| 208 |
cursor: pointer; |
| 209 |
opacity: 1 !important; |
| 210 |
|
| 211 |
&.el-select__clear { |
| 212 |
background: url('../../../assets/icons/global/fill-duo/close-circle.svg') no-repeat center; |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
&.is-secondary .el-select__wrapper { |
| 218 |
&:active, |
| 219 |
&:focus, |
| 220 |
&.is-focused, |
| 221 |
&.is-active { |
| 222 |
border: 1px solid var(--map-base-purple-stroke-0) !important; |
| 223 |
|
| 224 |
.el-tag { |
| 225 |
background: var(--map-base-purple-o10); |
| 226 |
color: var(--map-base-purple-symbol-0); |
| 227 |
|
| 228 |
.el-tag__close svg { |
| 229 |
color: var(--map-base-purple-symbol-0); |
| 230 |
width: 14px; |
| 231 |
height: 14px; |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
// Readonly |
| 238 |
&.is-readonly { |
| 239 |
pointer-events: none; |
| 240 |
|
| 241 |
.el-select__wrapper { |
| 242 |
cursor: default; |
| 243 |
|
| 244 |
// Keep normal opacity unlike disabled state |
| 245 |
opacity: 1; |
| 246 |
background: var(--map-base-dusk-o05); |
| 247 |
|
| 248 |
&:hover, |
| 249 |
&.is-hovering, |
| 250 |
&:focus, |
| 251 |
&:active, |
| 252 |
&.is-active, |
| 253 |
&.is-focused { |
| 254 |
border: 1px solid var(--map-base-dusk-stroke--2); |
| 255 |
cursor: default; |
| 256 |
} |
| 257 |
|
| 258 |
.el-select__suffix .el-icon.el-select__caret.el-select__icon { |
| 259 |
display: none; |
| 260 |
} |
| 261 |
|
| 262 |
// Maintain normal text color |
| 263 |
.el-select__selection { |
| 264 |
color: var(--map-base-text-0); |
| 265 |
cursor: default; |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
// Hide dropdown options |
| 270 |
.el-select-dropdown { |
| 271 |
display: none !important; |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
// Filled |
| 276 |
&.is-filled { |
| 277 |
.el-select__wrapper { |
| 278 |
border: 1px solid var(--map-base-dusk-stroke--2); |
| 279 |
background: var(--map-base-dusk-o05); |
| 280 |
|
| 281 |
&:hover, |
| 282 |
&.is-hovering { |
| 283 |
border: 1px solid var(--map-base-dusk-stroke-0); |
| 284 |
} |
| 285 |
|
| 286 |
&:active, |
| 287 |
&.is-active, |
| 288 |
&:focus, |
| 289 |
&.is-focused { |
| 290 |
border: 1px solid var(--map-base-brand-stroke-0); |
| 291 |
|
| 292 |
.el-tag { |
| 293 |
background: var(--map-base-brand-o10); |
| 294 |
color: var(--map-base-brand-symbol-0); |
| 295 |
|
| 296 |
.el-tag__close svg { |
| 297 |
color: var(--map-base-brand-symbol-0); |
| 298 |
width: 14px; |
| 299 |
height: 14px; |
| 300 |
} |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
.el-tag { |
| 305 |
background: var(--map-base-dusk-o20); |
| 306 |
color: var (--map-base-text-0); |
| 307 |
|
| 308 |
.el-tag__close svg { |
| 309 |
color: var(--map-base-text-0); |
| 310 |
width: 14px; |
| 311 |
height: 14px; |
| 312 |
} |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
&.is-error .el-select__wrapper { |
| 317 |
border: 1px solid var(--map-status-error-symbol-0); |
| 318 |
} |
| 319 |
|
| 320 |
&.is-warning .el-select__wrapper { |
| 321 |
border: 1px solid var(--map-status-warning-stroke-0); |
| 322 |
} |
| 323 |
|
| 324 |
.el-tag { |
| 325 |
font-size: 14px; |
| 326 |
font-weight: 400; |
| 327 |
line-height: 20px; |
| 328 |
display: flex; |
| 329 |
padding: 2px 4px 2px 8px; |
| 330 |
align-items: center; |
| 331 |
gap: 4px; |
| 332 |
cursor: pointer; |
| 333 |
background: var(--map-base-dusk-o20); |
| 334 |
color: var(--map-base-text-0); |
| 335 |
|
| 336 |
.el-tag__close { |
| 337 |
background: url('../../../assets/icons/global/outline/close.svg') no-repeat center; |
| 338 |
background-size: contain; |
| 339 |
width: 16px; |
| 340 |
height: 16px; |
| 341 |
cursor: pointer; |
| 342 |
margin: 0; |
| 343 |
|
| 344 |
svg { |
| 345 |
color: var(--map-base-text-0); |
| 346 |
width: 14px; |
| 347 |
height: 14px; |
| 348 |
} |
| 349 |
|
| 350 |
&:hover { |
| 351 |
background: url('../../../assets/icons/global/outline/close.svg') no-repeat center; |
| 352 |
width: 16px; |
| 353 |
height: 16px; |
| 354 |
} |
| 355 |
} |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
// Option Tag |
| 360 |
.el-tag--info { |
| 361 |
background: var(--map-base-dusk-o10); |
| 362 |
.el-select__tags-text { |
| 363 |
color: var(--map-base-text-0); |
| 364 |
} |
| 365 |
} |
| 366 |
} |
| 367 |
|
| 368 |
.el-select__popper { |
| 369 |
.el-scrollbar { |
| 370 |
border-radius: 3px; |
| 371 |
max-height: 161px; |
| 372 |
|
| 373 |
.el-select-dropdown__wrap { |
| 374 |
max-height: 161px; |
| 375 |
} |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
.el-form-item { |
| 380 |
&.is-error { |
| 381 |
.ivyforms-form-item-select.is-error { |
| 382 |
.el-select__wrapper { |
| 383 |
border: 1px solid var(--map-status-error-symbol-0); |
| 384 |
} |
| 385 |
} |
| 386 |
} |
| 387 |
} |
| 388 |
</style> |
| 389 |
|