@m3ui-vue/m3ui-vue 1.5.0 → 1.5.1
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/dist/API.md +1 -1
- package/dist/{MTextField-B72dwF6V.js → MTextField-BRntFeNR.js} +112 -78
- package/dist/MTextField-BRntFeNR.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/composables/_fieldLayout.d.ts +47 -0
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +3941 -3958
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +1 -1
- package/dist/pdf.js +1 -1
- package/dist/rich-text-editor.js +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/__tests__/fieldOverflow.test.ts +118 -0
- package/src/components/MAutocomplete.vue +21 -24
- package/src/components/MColorPicker.vue +3 -3
- package/src/components/MDatePicker.vue +4 -4
- package/src/components/MDateRangePicker.vue +4 -4
- package/src/components/MMaskField.vue +16 -24
- package/src/components/MMultiAutocomplete.vue +19 -25
- package/src/components/MMultiSelect.vue +20 -27
- package/src/components/MNumberField.vue +16 -26
- package/src/components/MPinInput.vue +3 -2
- package/src/components/MSearchBar.vue +2 -2
- package/src/components/MSelect.vue +16 -22
- package/src/components/MTagInput.vue +19 -26
- package/src/components/MTextField.vue +18 -46
- package/src/components/MTimePicker.vue +4 -4
- package/src/composables/_fieldLayout.ts +117 -0
- package/dist/MTextField-B72dwF6V.js.map +0 -1
|
@@ -13,6 +13,7 @@ import { useFieldBg } from '../composables/useFieldBg'
|
|
|
13
13
|
import { useLocale } from '../composables/useLocale'
|
|
14
14
|
import { POPUP_MARGIN, dropdownX, fitPopup } from '../composables/_popupPosition'
|
|
15
15
|
import { isoDate as fmt, useCalendarMonth } from '../composables/_useCalendarMonth'
|
|
16
|
+
import { OUTLINED_FLOATED_LABEL, vOverflowTitle } from '../composables/_fieldLayout'
|
|
16
17
|
|
|
17
18
|
export interface DateRange {
|
|
18
19
|
start: string | null
|
|
@@ -214,8 +215,8 @@ onUnmounted(() => {
|
|
|
214
215
|
@click="!disabled && (open = !open)"
|
|
215
216
|
>
|
|
216
217
|
<MIcon name="date_range" :size="24" class="shrink-0" :class="disabled ? 'text-on-surface/38' : 'text-on-surface-variant'" />
|
|
217
|
-
<span v-if="displayValue" class="flex-1" :class="disabled ? 'text-on-surface/38' : 'text-on-surface'">{{ displayValue }}</span>
|
|
218
|
-
<span v-else class="flex-1" :class="disabled ? 'text-on-surface/38' : 'text-on-surface-variant'">{{ label || placeholder || localeStrings.selectRange }}</span>
|
|
218
|
+
<span v-overflow-title v-if="displayValue" class="min-w-0 truncate flex-1" :class="disabled ? 'text-on-surface/38' : 'text-on-surface'">{{ displayValue }}</span>
|
|
219
|
+
<span v-overflow-title v-else class="min-w-0 truncate flex-1" :class="disabled ? 'text-on-surface/38' : 'text-on-surface-variant'">{{ label || placeholder || localeStrings.selectRange }}</span>
|
|
219
220
|
<MIcon
|
|
220
221
|
v-if="modelValue.start || modelValue.end"
|
|
221
222
|
name="close"
|
|
@@ -226,8 +227,7 @@ onUnmounted(() => {
|
|
|
226
227
|
</button>
|
|
227
228
|
<label
|
|
228
229
|
v-if="label"
|
|
229
|
-
class="
|
|
230
|
-
:class="disabled ? 'text-on-surface/38' : open ? (error ? 'text-error' : 'text-primary') : error ? 'text-error' : 'text-on-surface-variant'"
|
|
230
|
+
:class="[OUTLINED_FLOATED_LABEL, 'transition-colors', disabled ? 'text-on-surface/38' : open ? (error ? 'text-error' : 'text-primary') : error ? 'text-error' : 'text-on-surface-variant']"
|
|
231
231
|
>
|
|
232
232
|
{{ label }}
|
|
233
233
|
</label>
|
|
@@ -10,6 +10,7 @@ import MIcon from './MIcon.vue'
|
|
|
10
10
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
11
11
|
import { useDebounce } from '../composables/useDebounce'
|
|
12
12
|
import { useLocale } from '../composables/useLocale'
|
|
13
|
+
import { FIELD_PADDING_RIGHT, fieldLabelClasses, vOverflowTitle, type FieldRightInset } from '../composables/_fieldLayout'
|
|
13
14
|
|
|
14
15
|
export type MaskPreset = 'credit-card' | 'phone' | 'date' | 'time' | 'cpf' | 'cnpj' | 'zip'
|
|
15
16
|
|
|
@@ -128,9 +129,12 @@ function onKeydown(e: KeyboardEvent) {
|
|
|
128
129
|
|
|
129
130
|
const hasTrailing = computed(() => props.clearable)
|
|
130
131
|
|
|
132
|
+
// The label and the text both stop before the trailing controls
|
|
133
|
+
const rightInset = computed<FieldRightInset>(() => (hasTrailing.value ? 'right-12' : 'right-4'))
|
|
134
|
+
|
|
131
135
|
const inputClasses = computed(() => {
|
|
132
136
|
const pl = props.leadingIcon ? 'pl-12' : 'pl-4'
|
|
133
|
-
const pr =
|
|
137
|
+
const pr = FIELD_PADDING_RIGHT[rightInset.value]
|
|
134
138
|
const base = [
|
|
135
139
|
'peer block w-full text-body-large text-on-surface outline-none placeholder:text-transparent',
|
|
136
140
|
'transition-[border-color,border-width] duration-150',
|
|
@@ -156,31 +160,18 @@ const inputClasses = computed(() => {
|
|
|
156
160
|
].join(' ')
|
|
157
161
|
})
|
|
158
162
|
|
|
159
|
-
const labelClasses = computed(() =>
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
:
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
left, 'right-4', `${unfloatedTop} -translate-y-1/2 text-body-large`,
|
|
167
|
-
]
|
|
168
|
-
if (props.variant === 'outlined') {
|
|
169
|
-
return [...base,
|
|
170
|
-
'peer-focus:-top-2.5 peer-focus:translate-y-0 peer-focus:text-label-small peer-focus:right-auto peer-focus:max-w-[calc(100%-1.5rem)] peer-focus:bg-[var(--field-bg)] peer-focus:px-1',
|
|
171
|
-
'peer-[&:not(:placeholder-shown)]:-top-2.5 peer-[&:not(:placeholder-shown)]:translate-y-0 peer-[&:not(:placeholder-shown)]:right-auto peer-[&:not(:placeholder-shown)]:max-w-[calc(100%-1.5rem)]',
|
|
172
|
-
'peer-[&:not(:placeholder-shown)]:text-label-small peer-[&:not(:placeholder-shown)]:bg-[var(--field-bg)] peer-[&:not(:placeholder-shown)]:px-1',
|
|
163
|
+
const labelClasses = computed(() =>
|
|
164
|
+
fieldLabelClasses({
|
|
165
|
+
variant: props.variant,
|
|
166
|
+
leading: !!props.leadingIcon,
|
|
167
|
+
right: rightInset.value,
|
|
168
|
+
floated: 'peer',
|
|
169
|
+
color: [
|
|
173
170
|
props.error ? 'text-error peer-focus:text-error' : 'text-on-surface-variant peer-focus:text-primary',
|
|
174
171
|
'peer-disabled:text-on-surface/38',
|
|
175
|
-
].join(' ')
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
'peer-focus:top-2 peer-focus:translate-y-0 peer-focus:text-label-small',
|
|
179
|
-
'peer-[&:not(:placeholder-shown)]:top-2 peer-[&:not(:placeholder-shown)]:translate-y-0 peer-[&:not(:placeholder-shown)]:text-label-small',
|
|
180
|
-
props.error ? 'text-error peer-focus:text-error' : 'text-on-surface-variant peer-focus:text-primary',
|
|
181
|
-
'peer-disabled:text-on-surface/38',
|
|
182
|
-
].join(' ')
|
|
183
|
-
})
|
|
172
|
+
].join(' '),
|
|
173
|
+
}),
|
|
174
|
+
)
|
|
184
175
|
|
|
185
176
|
defineExpose({
|
|
186
177
|
/** The `<input>` (or `<textarea>`) element */
|
|
@@ -225,6 +216,7 @@ defineExpose({
|
|
|
225
216
|
:required="required"
|
|
226
217
|
placeholder=" "
|
|
227
218
|
:class="inputClasses"
|
|
219
|
+
v-overflow-title
|
|
228
220
|
@input="onInput"
|
|
229
221
|
@keydown="onKeydown"
|
|
230
222
|
/>
|
|
@@ -15,6 +15,7 @@ import { useDebounce } from '../composables/useDebounce'
|
|
|
15
15
|
import type { MultiSelectOption } from './MMultiSelect.vue'
|
|
16
16
|
import { useScrollLock } from '../composables/_useScrollLock'
|
|
17
17
|
import { useEscapeStack } from '../composables/_useEscapeStack'
|
|
18
|
+
import { FIELD_PADDING_RIGHT, fieldLabelClasses, vOverflowTitle, type FieldRightInset } from '../composables/_fieldLayout'
|
|
18
19
|
|
|
19
20
|
// Root is a fragment (field div + a sibling Teleport for the dropdown panel), so Vue can't
|
|
20
21
|
// auto-apply a consumer's class/attrs to either one — forward them onto the field div below.
|
|
@@ -323,11 +324,15 @@ watch(filteredOptions, () => {
|
|
|
323
324
|
|
|
324
325
|
const isFloated = computed(() => hasValue.value || open.value)
|
|
325
326
|
|
|
327
|
+
// Chips wrap before the trailing controls; the label stops there too
|
|
328
|
+
const rightInset = computed<FieldRightInset>(() => (props.clearable ? 'right-16' : 'right-10'))
|
|
329
|
+
|
|
326
330
|
const triggerClasses = computed(() => {
|
|
327
331
|
const base = [
|
|
328
|
-
'flex min-h-[56px] w-full items-center gap-1.5 flex-wrap',
|
|
332
|
+
'flex min-h-[56px] w-full min-w-0 items-center gap-1.5 flex-wrap',
|
|
329
333
|
'transition-[border-color,border-width] duration-150',
|
|
330
|
-
props.leadingIcon ? 'pl-12
|
|
334
|
+
props.leadingIcon ? 'pl-12' : 'pl-4',
|
|
335
|
+
FIELD_PADDING_RIGHT[rightInset.value],
|
|
331
336
|
]
|
|
332
337
|
|
|
333
338
|
if (props.variant === 'outlined') {
|
|
@@ -350,30 +355,19 @@ const triggerClasses = computed(() => {
|
|
|
350
355
|
return [...base, 'rounded-t-xs border-b pb-2', isFloated.value ? 'pt-7' : 'pt-4', bg, border].join(' ')
|
|
351
356
|
})
|
|
352
357
|
|
|
353
|
-
const labelClasses = computed(() =>
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
:
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
: 'top-2 translate-y-0 text-label-small'
|
|
361
|
-
|
|
362
|
-
const unFloated = props.variant === 'filled'
|
|
363
|
-
? 'top-[53%] -translate-y-1/2 text-body-large'
|
|
364
|
-
: 'top-1/2 -translate-y-1/2 text-body-large'
|
|
365
|
-
|
|
366
|
-
return [
|
|
367
|
-
'pointer-events-none absolute right-10 truncate transition-all duration-200',
|
|
368
|
-
left,
|
|
369
|
-
isFloated.value ? floated : unFloated,
|
|
370
|
-
props.disabled
|
|
358
|
+
const labelClasses = computed(() =>
|
|
359
|
+
fieldLabelClasses({
|
|
360
|
+
variant: props.variant,
|
|
361
|
+
leading: !!props.leadingIcon,
|
|
362
|
+
right: rightInset.value,
|
|
363
|
+
floated: isFloated.value,
|
|
364
|
+
color: props.disabled
|
|
371
365
|
? 'text-on-surface/38'
|
|
372
366
|
: open.value
|
|
373
367
|
? (props.error ? 'text-error' : 'text-primary')
|
|
374
368
|
: (props.error ? 'text-error' : 'text-on-surface-variant'),
|
|
375
|
-
|
|
376
|
-
|
|
369
|
+
}),
|
|
370
|
+
)
|
|
377
371
|
</script>
|
|
378
372
|
|
|
379
373
|
<template>
|
|
@@ -408,15 +402,15 @@ const labelClasses = computed(() => {
|
|
|
408
402
|
<span
|
|
409
403
|
v-for="(chip, i) in displayChips"
|
|
410
404
|
:key="i"
|
|
411
|
-
class="inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-label-small"
|
|
405
|
+
class="inline-flex max-w-full min-w-0 items-center gap-1 rounded-full px-2 py-0.5 text-label-small"
|
|
412
406
|
:class="disabled ? 'bg-on-surface/12 text-on-surface/38' : 'bg-secondary-container text-on-secondary-container'"
|
|
413
407
|
>
|
|
414
|
-
{{ chip.label }}
|
|
408
|
+
<span v-overflow-title class="min-w-0 truncate">{{ chip.label }}</span>
|
|
415
409
|
<button
|
|
416
410
|
:aria-label="`${locale.remove} ${chip.label}`"
|
|
417
411
|
v-if="!disabled"
|
|
418
412
|
type="button"
|
|
419
|
-
class="flex h-4 w-4 items-center justify-center rounded-full hover:bg-on-secondary-container/20"
|
|
413
|
+
class="flex h-4 w-4 shrink-0 items-center justify-center rounded-full hover:bg-on-secondary-container/20"
|
|
420
414
|
@click="removeChip(chip.value, $event)"
|
|
421
415
|
>
|
|
422
416
|
<MIcon name="close" :size="12" />
|
|
@@ -12,6 +12,7 @@ import MCheckbox from './MCheckbox.vue'
|
|
|
12
12
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
13
13
|
import { useLocale } from '../composables/useLocale'
|
|
14
14
|
import { useScrollLock } from '../composables/_useScrollLock'
|
|
15
|
+
import { FIELD_PADDING_RIGHT, FIELD_VALUE, fieldLabelClasses, vOverflowTitle, type FieldRightInset } from '../composables/_fieldLayout'
|
|
15
16
|
|
|
16
17
|
const locale = useLocale()
|
|
17
18
|
|
|
@@ -223,12 +224,16 @@ onUnmounted(() => {
|
|
|
223
224
|
window.removeEventListener('scroll', onScroll, true)
|
|
224
225
|
})
|
|
225
226
|
|
|
227
|
+
// Chips wrap before the trailing controls; the label stops there too
|
|
228
|
+
const rightInset = computed<FieldRightInset>(() => (props.clearable ? 'right-16' : 'right-10'))
|
|
229
|
+
|
|
226
230
|
const triggerClasses = computed(() => {
|
|
227
231
|
const base = [
|
|
228
|
-
'flex min-h-[56px] w-full items-center gap-1.5 flex-wrap outline-none',
|
|
232
|
+
'flex min-h-[56px] w-full min-w-0 items-center gap-1.5 flex-wrap outline-none',
|
|
229
233
|
'transition-[border-color,border-width] duration-150',
|
|
230
234
|
props.disabled ? 'cursor-not-allowed' : 'cursor-pointer',
|
|
231
|
-
props.leadingIcon ? 'pl-12
|
|
235
|
+
props.leadingIcon ? 'pl-12' : 'pl-4',
|
|
236
|
+
FIELD_PADDING_RIGHT[rightInset.value],
|
|
232
237
|
]
|
|
233
238
|
|
|
234
239
|
if (props.variant === 'outlined') {
|
|
@@ -257,31 +262,19 @@ const triggerClasses = computed(() => {
|
|
|
257
262
|
].join(' ')
|
|
258
263
|
})
|
|
259
264
|
|
|
260
|
-
const labelClasses = computed(() =>
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
:
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
: 'top-2 translate-y-0 text-label-small'
|
|
268
|
-
|
|
269
|
-
const unFloated = props.variant === 'filled'
|
|
270
|
-
? 'top-[53%] -translate-y-1/2 text-body-large'
|
|
271
|
-
: 'top-1/2 -translate-y-1/2 text-body-large'
|
|
272
|
-
const active = highlighted.value || hasValue.value
|
|
273
|
-
|
|
274
|
-
return [
|
|
275
|
-
'pointer-events-none absolute right-10 truncate transition-all duration-200',
|
|
276
|
-
left,
|
|
277
|
-
active ? floated : unFloated,
|
|
278
|
-
props.disabled
|
|
265
|
+
const labelClasses = computed(() =>
|
|
266
|
+
fieldLabelClasses({
|
|
267
|
+
variant: props.variant,
|
|
268
|
+
leading: !!props.leadingIcon,
|
|
269
|
+
right: rightInset.value,
|
|
270
|
+
floated: highlighted.value || hasValue.value,
|
|
271
|
+
color: props.disabled
|
|
279
272
|
? 'text-on-surface/38'
|
|
280
273
|
: highlighted.value
|
|
281
274
|
? (props.error ? 'text-error' : 'text-primary')
|
|
282
275
|
: (props.error ? 'text-error' : 'text-on-surface-variant'),
|
|
283
|
-
|
|
284
|
-
|
|
276
|
+
}),
|
|
277
|
+
)
|
|
285
278
|
</script>
|
|
286
279
|
|
|
287
280
|
<template>
|
|
@@ -324,15 +317,15 @@ const labelClasses = computed(() => {
|
|
|
324
317
|
<span
|
|
325
318
|
v-for="(chip, i) in displayChips"
|
|
326
319
|
:key="i"
|
|
327
|
-
class="inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-label-small"
|
|
320
|
+
class="inline-flex max-w-full min-w-0 items-center gap-1 rounded-full px-2 py-0.5 text-label-small"
|
|
328
321
|
:class="disabled ? 'bg-on-surface/12 text-on-surface/38' : 'bg-secondary-container text-on-secondary-container'"
|
|
329
322
|
>
|
|
330
|
-
{{ chip.label }}
|
|
323
|
+
<span v-overflow-title class="min-w-0 truncate">{{ chip.label }}</span>
|
|
331
324
|
<button
|
|
332
325
|
:aria-label="`${locale.remove} ${chip.label}`"
|
|
333
326
|
v-if="!disabled"
|
|
334
327
|
type="button"
|
|
335
|
-
class="flex h-4 w-4 items-center justify-center rounded-full hover:bg-on-secondary-container/20"
|
|
328
|
+
class="flex h-4 w-4 shrink-0 items-center justify-center rounded-full hover:bg-on-secondary-container/20"
|
|
336
329
|
@click="removeChip(chip.value, $event)"
|
|
337
330
|
>
|
|
338
331
|
<MIcon name="close" :size="12" />
|
|
@@ -354,7 +347,7 @@ const labelClasses = computed(() => {
|
|
|
354
347
|
<MIcon name="unfold_less" :size="14" />
|
|
355
348
|
</span>
|
|
356
349
|
</template>
|
|
357
|
-
<span v-else-if="!open" class="text-body-large text-on-surface-variant opacity-0">
|
|
350
|
+
<span v-else-if="!open" :class="[FIELD_VALUE, 'text-body-large text-on-surface-variant opacity-0']">
|
|
358
351
|
{{ placeholder }}
|
|
359
352
|
</span>
|
|
360
353
|
</div>
|
|
@@ -11,6 +11,7 @@ import MIcon from './MIcon.vue'
|
|
|
11
11
|
import MIconButton from './MIconButton.vue'
|
|
12
12
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
13
13
|
import { useDebounce } from '../composables/useDebounce'
|
|
14
|
+
import { FIELD_PADDING_RIGHT, fieldLabelClasses, vOverflowTitle, type FieldRightInset } from '../composables/_fieldLayout'
|
|
14
15
|
|
|
15
16
|
const props = withDefaults(
|
|
16
17
|
defineProps<{
|
|
@@ -107,9 +108,12 @@ function onKeydown(e: KeyboardEvent) {
|
|
|
107
108
|
if (e.key === 'ArrowDown') { e.preventDefault(); decrement() }
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
// The label and the text both stop before the trailing controls
|
|
112
|
+
const rightInset = computed<FieldRightInset>(() => (props.stepper ? 'right-24' : 'right-4'))
|
|
113
|
+
|
|
110
114
|
const inputClasses = computed(() => {
|
|
111
115
|
const pl = props.leadingIcon ? 'pl-12' : 'pl-4'
|
|
112
|
-
const pr =
|
|
116
|
+
const pr = FIELD_PADDING_RIGHT[rightInset.value]
|
|
113
117
|
const base = [
|
|
114
118
|
'peer block w-full text-body-large text-on-surface outline-none placeholder:text-transparent',
|
|
115
119
|
'transition-[border-color,border-width] duration-150',
|
|
@@ -135,33 +139,18 @@ const inputClasses = computed(() => {
|
|
|
135
139
|
].join(' ')
|
|
136
140
|
})
|
|
137
141
|
|
|
138
|
-
const labelClasses = computed(() =>
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
'pointer-events-none absolute truncate transition-all duration-200',
|
|
146
|
-
left, 'right-4', `${unfloatedTop} -translate-y-1/2 text-body-large`,
|
|
147
|
-
]
|
|
148
|
-
|
|
149
|
-
if (props.variant === 'outlined') {
|
|
150
|
-
return [...base,
|
|
151
|
-
'peer-focus:-top-2.5 peer-focus:translate-y-0 peer-focus:text-label-small peer-focus:right-auto peer-focus:max-w-[calc(100%-1.5rem)] peer-focus:bg-[var(--field-bg)] peer-focus:px-1',
|
|
152
|
-
'peer-[&:not(:placeholder-shown)]:-top-2.5 peer-[&:not(:placeholder-shown)]:translate-y-0 peer-[&:not(:placeholder-shown)]:right-auto peer-[&:not(:placeholder-shown)]:max-w-[calc(100%-1.5rem)]',
|
|
153
|
-
'peer-[&:not(:placeholder-shown)]:text-label-small peer-[&:not(:placeholder-shown)]:bg-[var(--field-bg)] peer-[&:not(:placeholder-shown)]:px-1',
|
|
142
|
+
const labelClasses = computed(() =>
|
|
143
|
+
fieldLabelClasses({
|
|
144
|
+
variant: props.variant,
|
|
145
|
+
leading: !!props.leadingIcon,
|
|
146
|
+
right: rightInset.value,
|
|
147
|
+
floated: 'peer',
|
|
148
|
+
color: [
|
|
154
149
|
props.error ? 'text-error peer-focus:text-error' : 'text-on-surface-variant peer-focus:text-primary',
|
|
155
150
|
'peer-disabled:text-on-surface/38',
|
|
156
|
-
].join(' ')
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
'peer-focus:top-2 peer-focus:translate-y-0 peer-focus:text-label-small',
|
|
160
|
-
'peer-[&:not(:placeholder-shown)]:top-2 peer-[&:not(:placeholder-shown)]:translate-y-0 peer-[&:not(:placeholder-shown)]:text-label-small',
|
|
161
|
-
props.error ? 'text-error peer-focus:text-error' : 'text-on-surface-variant peer-focus:text-primary',
|
|
162
|
-
'peer-disabled:text-on-surface/38',
|
|
163
|
-
].join(' ')
|
|
164
|
-
})
|
|
151
|
+
].join(' '),
|
|
152
|
+
}),
|
|
153
|
+
)
|
|
165
154
|
|
|
166
155
|
defineExpose({
|
|
167
156
|
/** The `<input>` (or `<textarea>`) element */
|
|
@@ -206,6 +195,7 @@ defineExpose({
|
|
|
206
195
|
:step="step"
|
|
207
196
|
placeholder=" "
|
|
208
197
|
:class="inputClasses"
|
|
198
|
+
v-overflow-title
|
|
209
199
|
@input="onInput"
|
|
210
200
|
@keydown="onKeydown"
|
|
211
201
|
/>
|
|
@@ -167,7 +167,8 @@ watch(
|
|
|
167
167
|
|
|
168
168
|
const boxClasses = computed(() => {
|
|
169
169
|
const base = [
|
|
170
|
-
|
|
170
|
+
// Shrinks below 48px when the row is narrower than all the boxes (flex: 0 1 3rem)
|
|
171
|
+
'h-14 w-12 min-w-0 shrink text-center text-title-large outline-none',
|
|
171
172
|
'transition-[border-color,border-width] duration-150',
|
|
172
173
|
'disabled:cursor-not-allowed disabled:text-on-surface/38',
|
|
173
174
|
props.error ? 'caret-error' : 'caret-primary',
|
|
@@ -193,7 +194,7 @@ const boxClasses = computed(() => {
|
|
|
193
194
|
|
|
194
195
|
<template>
|
|
195
196
|
<div class="flex flex-col gap-1">
|
|
196
|
-
<div role="group" :aria-label="label" class="flex items-center gap-2">
|
|
197
|
+
<div role="group" :aria-label="label" class="flex min-w-0 items-center gap-2">
|
|
197
198
|
<template v-for="(digit, i) in digits" :key="i">
|
|
198
199
|
<input
|
|
199
200
|
:ref="(el) => setInputEl(el, i)"
|
|
@@ -183,7 +183,7 @@ useEscapeStack(() => expanded.value, () => close())
|
|
|
183
183
|
:placeholder="placeholder ?? locale.search"
|
|
184
184
|
:disabled="disabled"
|
|
185
185
|
:aria-expanded="expanded"
|
|
186
|
-
class="w-full bg-transparent text-body-large text-on-surface outline-none placeholder:text-on-surface-variant"
|
|
186
|
+
class="w-full min-w-0 bg-transparent text-body-large text-on-surface outline-none placeholder:text-on-surface-variant text-ellipsis"
|
|
187
187
|
:class="textAlign === 'center' ? 'text-center' : ''"
|
|
188
188
|
@focus="open"
|
|
189
189
|
@input="onInput"
|
|
@@ -233,7 +233,7 @@ useEscapeStack(() => expanded.value, () => close())
|
|
|
233
233
|
role="searchbox"
|
|
234
234
|
:value="modelValue"
|
|
235
235
|
:placeholder="placeholder ?? locale.search"
|
|
236
|
-
class="w-full bg-transparent text-body-large text-on-surface outline-none placeholder:text-on-surface-variant"
|
|
236
|
+
class="w-full min-w-0 bg-transparent text-body-large text-on-surface outline-none placeholder:text-on-surface-variant text-ellipsis"
|
|
237
237
|
:class="textAlign === 'center' ? 'text-center' : ''"
|
|
238
238
|
@input="onInput"
|
|
239
239
|
@keydown="onKeydown"
|
|
@@ -11,6 +11,7 @@ import { useFieldBg } from '../composables/useFieldBg'
|
|
|
11
11
|
import { useLocale } from '../composables/useLocale'
|
|
12
12
|
import { useScrollLock } from '../composables/_useScrollLock'
|
|
13
13
|
import { useEscapeStack } from '../composables/_useEscapeStack'
|
|
14
|
+
import { FIELD_PADDING_RIGHT, FIELD_VALUE, fieldLabelClasses, vOverflowTitle, type FieldRightInset } from '../composables/_fieldLayout'
|
|
14
15
|
|
|
15
16
|
export interface SelectOption {
|
|
16
17
|
label: string
|
|
@@ -179,12 +180,16 @@ onUnmounted(() => {
|
|
|
179
180
|
window.removeEventListener('scroll', onScroll, true)
|
|
180
181
|
})
|
|
181
182
|
|
|
183
|
+
// The value and the label stop before the clear button and the arrow
|
|
184
|
+
const rightInset = computed<FieldRightInset>(() => (props.clearable ? 'right-16' : 'right-10'))
|
|
185
|
+
|
|
182
186
|
const triggerClasses = computed(() => {
|
|
183
187
|
const pl = props.leadingIcon ? 'pl-12' : 'pl-4'
|
|
184
188
|
const base = [
|
|
185
|
-
'flex w-full items-center
|
|
189
|
+
'flex w-full min-w-0 items-center text-body-large outline-none transition-[border-color,border-width] duration-150',
|
|
186
190
|
props.disabled ? 'cursor-not-allowed' : 'cursor-pointer',
|
|
187
191
|
pl,
|
|
192
|
+
FIELD_PADDING_RIGHT[rightInset.value],
|
|
188
193
|
]
|
|
189
194
|
|
|
190
195
|
if (props.variant === 'outlined') {
|
|
@@ -209,30 +214,19 @@ const triggerClasses = computed(() => {
|
|
|
209
214
|
|
|
210
215
|
const isFloated = computed(() => hasValue.value || highlighted.value)
|
|
211
216
|
|
|
212
|
-
const labelClasses = computed(() =>
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
:
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
: 'top-2 translate-y-0 text-label-small'
|
|
220
|
-
|
|
221
|
-
const unFloated = props.variant === 'filled'
|
|
222
|
-
? 'top-[53%] -translate-y-1/2 text-body-large'
|
|
223
|
-
: 'top-1/2 -translate-y-1/2 text-body-large'
|
|
224
|
-
|
|
225
|
-
return [
|
|
226
|
-
'pointer-events-none absolute right-10 truncate transition-all duration-200',
|
|
227
|
-
left,
|
|
228
|
-
isFloated.value ? floated : unFloated,
|
|
229
|
-
props.disabled
|
|
217
|
+
const labelClasses = computed(() =>
|
|
218
|
+
fieldLabelClasses({
|
|
219
|
+
variant: props.variant,
|
|
220
|
+
leading: !!props.leadingIcon,
|
|
221
|
+
right: rightInset.value,
|
|
222
|
+
floated: isFloated.value,
|
|
223
|
+
color: props.disabled
|
|
230
224
|
? 'text-on-surface/38'
|
|
231
225
|
: highlighted.value
|
|
232
226
|
? (props.error ? 'text-error' : 'text-primary')
|
|
233
227
|
: (props.error ? 'text-error' : 'text-on-surface-variant'),
|
|
234
|
-
|
|
235
|
-
|
|
228
|
+
}),
|
|
229
|
+
)
|
|
236
230
|
</script>
|
|
237
231
|
|
|
238
232
|
<template>
|
|
@@ -274,7 +268,7 @@ const labelClasses = computed(() => {
|
|
|
274
268
|
@focus="focused = true"
|
|
275
269
|
@blur="focused = false"
|
|
276
270
|
>
|
|
277
|
-
<span v-if="hasValue" :class="disabled ? 'text-on-surface/38' : 'text-on-surface'">{{ selectedLabel }}</span>
|
|
271
|
+
<span v-if="hasValue" v-overflow-title :class="[FIELD_VALUE, disabled ? 'text-on-surface/38' : 'text-on-surface']">{{ selectedLabel }}</span>
|
|
278
272
|
</div>
|
|
279
273
|
|
|
280
274
|
<!-- Floating label -->
|
|
@@ -10,6 +10,7 @@ import MIcon from './MIcon.vue'
|
|
|
10
10
|
import { useFieldBg } from '../composables/useFieldBg'
|
|
11
11
|
import { useDebounce } from '../composables/useDebounce'
|
|
12
12
|
import { useLocale } from '../composables/useLocale'
|
|
13
|
+
import { FIELD_PADDING_RIGHT, fieldLabelClasses, vOverflowTitle, type FieldRightInset } from '../composables/_fieldLayout'
|
|
13
14
|
|
|
14
15
|
const locale = useLocale()
|
|
15
16
|
const props = withDefaults(
|
|
@@ -139,12 +140,16 @@ function focusInput() {
|
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
142
|
|
|
143
|
+
// Chips wrap before the trailing controls; the label stops there too
|
|
144
|
+
const rightInset = computed<FieldRightInset>(() => ('right-10'))
|
|
145
|
+
|
|
142
146
|
const triggerClasses = computed(() => {
|
|
143
147
|
const base = [
|
|
144
|
-
'flex min-h-[56px] w-full items-center gap-1.5 flex-wrap',
|
|
148
|
+
'flex min-h-[56px] w-full min-w-0 items-center gap-1.5 flex-wrap',
|
|
145
149
|
'transition-[border-color,border-width] duration-150',
|
|
146
150
|
props.disabled ? 'cursor-not-allowed' : 'cursor-text',
|
|
147
|
-
props.leadingIcon ? 'pl-12
|
|
151
|
+
props.leadingIcon ? 'pl-12' : 'pl-4',
|
|
152
|
+
FIELD_PADDING_RIGHT[rightInset.value],
|
|
148
153
|
]
|
|
149
154
|
|
|
150
155
|
if (props.variant === 'outlined') {
|
|
@@ -167,31 +172,19 @@ const triggerClasses = computed(() => {
|
|
|
167
172
|
return [...base, 'rounded-t-xs border-b pb-2', hasValue.value || focused.value ? 'pt-7' : 'pt-4', bg, border].join(' ')
|
|
168
173
|
})
|
|
169
174
|
|
|
170
|
-
const labelClasses = computed(() =>
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
: 'top-2 translate-y-0 text-label-small'
|
|
178
|
-
|
|
179
|
-
const unFloated = props.variant === 'filled'
|
|
180
|
-
? 'top-[53%] -translate-y-1/2 text-body-large'
|
|
181
|
-
: 'top-1/2 -translate-y-1/2 text-body-large'
|
|
182
|
-
const active = focused.value || hasValue.value
|
|
183
|
-
|
|
184
|
-
return [
|
|
185
|
-
'pointer-events-none absolute right-10 truncate transition-all duration-200',
|
|
186
|
-
left,
|
|
187
|
-
active ? floated : unFloated,
|
|
188
|
-
props.disabled
|
|
175
|
+
const labelClasses = computed(() =>
|
|
176
|
+
fieldLabelClasses({
|
|
177
|
+
variant: props.variant,
|
|
178
|
+
leading: !!props.leadingIcon,
|
|
179
|
+
right: rightInset.value,
|
|
180
|
+
floated: focused.value || hasValue.value,
|
|
181
|
+
color: props.disabled
|
|
189
182
|
? 'text-on-surface/38'
|
|
190
183
|
: focused.value
|
|
191
184
|
? (props.error ? 'text-error' : 'text-primary')
|
|
192
185
|
: (props.error ? 'text-error' : 'text-on-surface-variant'),
|
|
193
|
-
|
|
194
|
-
|
|
186
|
+
}),
|
|
187
|
+
)
|
|
195
188
|
|
|
196
189
|
defineExpose({
|
|
197
190
|
/** The `<input>` (or `<textarea>`) element */
|
|
@@ -235,15 +228,15 @@ defineExpose({
|
|
|
235
228
|
<span
|
|
236
229
|
v-for="(tag, i) in modelValue"
|
|
237
230
|
:key="i"
|
|
238
|
-
class="inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-label-small"
|
|
231
|
+
class="inline-flex max-w-full min-w-0 items-center gap-1 rounded-full px-2 py-0.5 text-label-small"
|
|
239
232
|
:class="disabled ? 'bg-on-surface/12 text-on-surface/38' : 'bg-secondary-container text-on-secondary-container'"
|
|
240
233
|
>
|
|
241
|
-
{{ tag }}
|
|
234
|
+
<span v-overflow-title class="min-w-0 truncate">{{ tag }}</span>
|
|
242
235
|
<button
|
|
243
236
|
:aria-label="`${locale.remove} ${tag}`"
|
|
244
237
|
v-if="!disabled"
|
|
245
238
|
type="button"
|
|
246
|
-
class="flex h-4 w-4 items-center justify-center rounded-full hover:bg-on-secondary-container/20"
|
|
239
|
+
class="flex h-4 w-4 shrink-0 items-center justify-center rounded-full hover:bg-on-secondary-container/20"
|
|
247
240
|
@click="removeTag(i, $event)"
|
|
248
241
|
>
|
|
249
242
|
<MIcon name="close" :size="12" />
|
|
@@ -13,6 +13,7 @@ import { useAutoGrow } from "../composables/useAutoGrow";
|
|
|
13
13
|
import { useFieldBg } from "../composables/useFieldBg";
|
|
14
14
|
import { useDebounce } from "../composables/useDebounce";
|
|
15
15
|
import { useLocale } from '../composables/useLocale'
|
|
16
|
+
import { FIELD_PADDING_RIGHT, fieldLabelClasses, vOverflowTitle, type FieldRightInset } from '../composables/_fieldLayout'
|
|
16
17
|
|
|
17
18
|
const locale = useLocale()
|
|
18
19
|
const props = withDefaults(
|
|
@@ -86,10 +87,12 @@ useAutoGrow(() => (props.multiline && props.autoGrow ? textareaEl.value : null),
|
|
|
86
87
|
|
|
87
88
|
const showClear = computed(() => props.clearable && String(props.modelValue).length > 0 && !props.disabled)
|
|
88
89
|
|
|
90
|
+
// The label and the text both stop before a trailing button (the #trailing slot or the clear button)
|
|
91
|
+
const rightInset = computed<FieldRightInset>(() => (slots.trailing || props.clearable ? "right-12" : "right-4"));
|
|
92
|
+
|
|
89
93
|
const inputClasses = computed(() => {
|
|
90
|
-
const hasTrailing = !!slots.trailing || props.clearable;
|
|
91
94
|
const pl = props.leadingIcon ? "pl-12" : "pl-4";
|
|
92
|
-
const pr =
|
|
95
|
+
const pr = FIELD_PADDING_RIGHT[rightInset.value];
|
|
93
96
|
const size = props.multiline ? (props.autoGrow ? "resize-none min-h-[56px]" : "resize-y min-h-[56px]") : "h-14";
|
|
94
97
|
const base = [
|
|
95
98
|
"peer block w-full text-body-large text-on-surface outline-none placeholder:text-transparent",
|
|
@@ -126,50 +129,18 @@ const inputClasses = computed(() => {
|
|
|
126
129
|
].join(" ");
|
|
127
130
|
});
|
|
128
131
|
|
|
129
|
-
const labelClasses = computed(() =>
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
:
|
|
135
|
-
|
|
136
|
-
:
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
left,
|
|
142
|
-
"right-4",
|
|
143
|
-
`${unfloatedTop} -translate-y-1/2 text-body-large`,
|
|
144
|
-
];
|
|
145
|
-
|
|
146
|
-
if (props.variant === "outlined") {
|
|
147
|
-
// When floated: drop right-4 (right-auto) and cap max-width so the label
|
|
148
|
-
// shrinks to its own text width. The bg then only covers the glyphs + px-1,
|
|
149
|
-
// cutting the border just where the text sits instead of a long strip.
|
|
150
|
-
return [
|
|
151
|
-
...base,
|
|
152
|
-
"peer-focus:-top-2.5 peer-focus:translate-y-0 peer-focus:text-label-small peer-focus:right-auto peer-focus:max-w-[calc(100%-1.5rem)] peer-focus:bg-[var(--field-bg)] peer-focus:px-1",
|
|
153
|
-
"peer-[&:not(:placeholder-shown)]:-top-2.5 peer-[&:not(:placeholder-shown)]:translate-y-0 peer-[&:not(:placeholder-shown)]:right-auto peer-[&:not(:placeholder-shown)]:max-w-[calc(100%-1.5rem)]",
|
|
154
|
-
"peer-[&:not(:placeholder-shown)]:text-label-small peer-[&:not(:placeholder-shown)]:bg-[var(--field-bg)] peer-[&:not(:placeholder-shown)]:px-1",
|
|
155
|
-
props.error
|
|
156
|
-
? "text-error peer-focus:text-error"
|
|
157
|
-
: "text-on-surface-variant peer-focus:text-primary",
|
|
158
|
-
"peer-disabled:text-on-surface/38",
|
|
159
|
-
].join(" ");
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Filled: label floats to top-2 (slightly higher than before)
|
|
163
|
-
return [
|
|
164
|
-
...base,
|
|
165
|
-
"peer-focus:top-2 peer-focus:translate-y-0 peer-focus:text-label-small",
|
|
166
|
-
"peer-[&:not(:placeholder-shown)]:top-2 peer-[&:not(:placeholder-shown)]:translate-y-0 peer-[&:not(:placeholder-shown)]:text-label-small",
|
|
167
|
-
props.error
|
|
168
|
-
? "text-error peer-focus:text-error"
|
|
169
|
-
: "text-on-surface-variant peer-focus:text-primary",
|
|
170
|
-
"peer-disabled:text-on-surface/38",
|
|
171
|
-
].join(" ");
|
|
172
|
-
});
|
|
132
|
+
const labelClasses = computed(() =>
|
|
133
|
+
fieldLabelClasses({
|
|
134
|
+
variant: props.variant,
|
|
135
|
+
leading: !!props.leadingIcon,
|
|
136
|
+
right: rightInset.value,
|
|
137
|
+
floated: 'peer',
|
|
138
|
+
color: [
|
|
139
|
+
props.error ? 'text-error peer-focus:text-error' : 'text-on-surface-variant peer-focus:text-primary',
|
|
140
|
+
'peer-disabled:text-on-surface/38',
|
|
141
|
+
].join(' '),
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
173
144
|
|
|
174
145
|
function onInput(event: Event) {
|
|
175
146
|
const target = event.target as HTMLInputElement | HTMLTextAreaElement;
|
|
@@ -238,6 +209,7 @@ defineExpose({
|
|
|
238
209
|
:autocomplete="autocomplete"
|
|
239
210
|
placeholder=" "
|
|
240
211
|
:class="inputClasses"
|
|
212
|
+
v-overflow-title
|
|
241
213
|
@input="onInput"
|
|
242
214
|
/>
|
|
243
215
|
|