Merge pull request #4014 from rommapp/fix/rselect-menu-overflow-and-separator

fix(v2): keep RSelect menus inside the viewport and tidy the selection text
This commit is contained in:
Georges-Antoine Assi
2026-07-30 19:25:46 -04:00
committed by GitHub
22 changed files with 92 additions and 26 deletions

View File

@@ -214,7 +214,7 @@
"media-box2d": "Обложка (2D)",
"media-box2d-back": "Задна корица",
"media-box2d-side": "Гръб на кутията",
"media-box3d": "3D обложка",
"media-box3d": "Обложка (3D)",
"media-fanart": "Фен арт",
"media-logo": "Лого",
"media-manual": "Ръководство",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Obal (2D)",
"media-box2d-back": "Zadní strana obalu",
"media-box2d-side": "Hřbet obalu",
"media-box3d": "3D obal",
"media-box3d": "Obal (3D)",
"media-fanart": "Fanouškovská grafika",
"media-logo": "Logo",
"media-manual": "Manuál",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Boxart (2D)",
"media-box2d-back": "Rückseite",
"media-box2d-side": "Box-Seitenteil",
"media-box3d": "3D-Boxart",
"media-box3d": "Boxart (3D)",
"media-fanart": "Fan-Art",
"media-logo": "Logo",
"media-manual": "Handbuch",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Box art (2D)",
"media-box2d-back": "Back cover",
"media-box2d-side": "Box spine",
"media-box3d": "3D box art",
"media-box3d": "Box art (3D)",
"media-fanart": "Fan art",
"media-logo": "Logo",
"media-manual": "Manual",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Box art (2D)",
"media-box2d-back": "Back cover",
"media-box2d-side": "Box spine",
"media-box3d": "3D box art",
"media-box3d": "Box art (3D)",
"media-fanart": "Fan art",
"media-logo": "Logo",
"media-manual": "Manual",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Carátula (2D)",
"media-box2d-back": "Contraportada",
"media-box2d-side": "Lomo de la caja",
"media-box3d": "Carátula 3D",
"media-box3d": "Carátula (3D)",
"media-fanart": "Fan art",
"media-logo": "Logo",
"media-manual": "Manual",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Jaquette (2D)",
"media-box2d-back": "Dos de la jaquette",
"media-box2d-side": "Tranche de la boîte",
"media-box3d": "Jaquette 3D",
"media-box3d": "Jaquette (3D)",
"media-fanart": "Fan art",
"media-logo": "Logo",
"media-manual": "Manuel",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Dobozkép (2D)",
"media-box2d-back": "Hátsó borító",
"media-box2d-side": "Doboz gerinc",
"media-box3d": "3D dobozkép",
"media-box3d": "Dobozkép (3D)",
"media-fanart": "Rajongói grafika",
"media-logo": "Logó",
"media-manual": "Kézikönyv",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Copertina (2D)",
"media-box2d-back": "Retro della copertina",
"media-box2d-side": "Dorso della scatola",
"media-box3d": "Copertina 3D",
"media-box3d": "Copertina (3D)",
"media-fanart": "Fan art",
"media-logo": "Logo",
"media-manual": "Manuale",

View File

@@ -214,7 +214,7 @@
"media-box2d": "ボックスアート(2D)",
"media-box2d-back": "背面カバー",
"media-box2d-side": "背表紙",
"media-box3d": "3Dボックスアート",
"media-box3d": "ボックスアート(3D)",
"media-fanart": "ファンアート",
"media-logo": "ロゴ",
"media-manual": "マニュアル",

View File

@@ -214,7 +214,7 @@
"media-box2d": "박스아트 (2D)",
"media-box2d-back": "뒷면 커버",
"media-box2d-side": "박스 측면",
"media-box3d": "3D 박스아트",
"media-box3d": "박스아트 (3D)",
"media-fanart": "팬아트",
"media-logo": "로고",
"media-manual": "매뉴얼",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Okładka (2D)",
"media-box2d-back": "Tylna okładka",
"media-box2d-side": "Grzbiet pudełka",
"media-box3d": "Okładka 3D",
"media-box3d": "Okładka (3D)",
"media-fanart": "Fan art",
"media-logo": "Logo",
"media-manual": "Instrukcja",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Capa (2D)",
"media-box2d-back": "Contracapa",
"media-box2d-side": "Lombada da caixa",
"media-box3d": "Capa 3D",
"media-box3d": "Capa (3D)",
"media-fanart": "Fan art",
"media-logo": "Logo",
"media-manual": "Manual",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Copertă (2D)",
"media-box2d-back": "Copertă spate",
"media-box2d-side": "Cotor cutie",
"media-box3d": "Copertă 3D",
"media-box3d": "Copertă (3D)",
"media-fanart": "Artă de fani",
"media-logo": "Logo",
"media-manual": "Manual",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Обложка (2D)",
"media-box2d-back": "Задняя обложка",
"media-box2d-side": "Корешок коробки",
"media-box3d": "3D-обложка",
"media-box3d": "Обложка (3D)",
"media-fanart": "Фан-арт",
"media-logo": "Логотип",
"media-manual": "Руководство",

View File

@@ -214,7 +214,7 @@
"media-box2d": "Kutu görseli (2D)",
"media-box2d-back": "Arka kapak",
"media-box2d-side": "Kutu sırtı",
"media-box3d": "3D kutu görseli",
"media-box3d": "Kutu görseli (3D)",
"media-fanart": "Hayran sanatı",
"media-logo": "Logo",
"media-manual": "Kılavuz",

View File

@@ -214,7 +214,7 @@
"media-box2d": "封面(2D)",
"media-box2d-back": "封底",
"media-box2d-side": "侧封",
"media-box3d": "3D封面",
"media-box3d": "封面(3D)",
"media-fanart": "同人插画",
"media-logo": "徽标",
"media-manual": "说明书",

View File

@@ -214,7 +214,7 @@
"media-box2d": "封面(2D)",
"media-box2d-back": "封底",
"media-box2d-side": "側封",
"media-box3d": "3D封面",
"media-box3d": "封面(3D)",
"media-fanart": "同人插畫",
"media-logo": "標誌",
"media-manual": "說明書",

View File

@@ -233,6 +233,18 @@ export const Multiple: Story = {
}),
};
// Without `chips` the selections render as one run of text. The comma
// separator must read "A, B" — a space on both sides means the separator
// picked up the value row's flex gap.
export const MultipleText: Story = {
name: "Multiple (no chips)",
render: () => ({
components: { RSelect },
setup: () => ({ value: ref(["psx", "snes"]), items: PLATFORMS }),
template: `<div style="width:480px"><RSelect v-model="value" :items="items" multiple placeholder="Pick platforms" /></div>`,
}),
};
export const MultipleOverflow: Story = {
name: "Multiple · dynamic overflow",
render: () => ({

View File

@@ -0,0 +1,31 @@
import { mount } from "@vue/test-utils";
import { describe, expect, it } from "vitest";
import RSelect from "./RSelect.vue";
// Regression guard: `.r-select__value` is a flex row with a 6px gap (it
// spaces chips apart). A multi-select without chips renders its titles and
// the "," separator as plain spans, so hoisting them into that row put the
// gap on both sides of the comma and the activator read "A , B".
describe("RSelect multi-select without chips", () => {
const items = [
{ title: "Screenshot", value: "screenshot" },
{ title: "Manual", value: "manual" },
];
it("keeps the titles and separator in one box inside the value row", () => {
const wrapper = mount(RSelect, {
props: { items, multiple: true, modelValue: ["screenshot", "manual"] },
});
const value = wrapper.get(".r-select__value");
expect(value.element.children).toHaveLength(1);
const selection = wrapper.get(".r-select__selection");
expect(selection.findAll(".r-select__title").map((n) => n.text())).toEqual([
"Screenshot",
"Manual",
]);
expect(selection.findAll(".r-select__sep")).toHaveLength(1);
expect(selection.text()).toBe("Screenshot, Manual");
});
});

View File

@@ -653,6 +653,9 @@ const isOpen = ref(false);
const activatorRef = ref<HTMLElement | null>(null);
const panelRef = ref<HTMLElement | null>(null);
// Ceiling for the panel; the viewport remainder can shrink it further.
const MAX_PANEL_HEIGHT = 360;
const PLACEMENT_MAP: Record<string, Placement> = {
top: "top",
bottom: "bottom",
@@ -676,14 +679,15 @@ const { floatingStyles } = useFloating(activatorRef, panelRef, {
flip({ padding: 8 }),
shift({ padding: 8 }),
sizeMiddleware({
apply({ rects, elements }) {
apply({ availableHeight, rects, elements }) {
// Pin the menu's min-width to the activator so single-line
// labels and short option lists don't render as a thin chip.
// Max height is bounded by the viewport remainder so long
// lists scroll inside the panel.
// `availableHeight` is the room left between the activator and
// the viewport edge on the placement `flip` settled on, so the
// panel always fits on screen and long lists scroll inside it.
Object.assign(elements.floating.style, {
minWidth: `${rects.reference.width}px`,
maxHeight: `min(360px, var(--available-height, 360px))`,
maxHeight: `${Math.min(MAX_PANEL_HEIGHT, availableHeight)}px`,
});
},
padding: 8,
@@ -1035,8 +1039,10 @@ const hasPrependInner = computed(
/>
</template>
<!-- Single selection or multi-without-chips — defer to the
`#selection` slot for custom rendering. Default: title. -->
<template v-else>
`#selection` slot for custom rendering. Default: title.
Wrapped in one box so the comma separator doesn't inherit
`.r-select__value`'s flex gap and read as " , ". -->
<span v-else class="r-select__selection">
<template v-for="(item, i) in selectedItems" :key="i">
<slot
name="selection"
@@ -1047,7 +1053,7 @@ const hasPrependInner = computed(
<span class="r-select__title">{{ item.title }}</span>
</slot>
</template>
</template>
</span>
</span>
<span
@@ -1378,12 +1384,26 @@ const hasPrependInner = computed(
gap: 6px;
white-space: nowrap;
}
.r-select__selection {
display: flex;
align-items: center;
min-width: 0;
overflow: hidden;
}
.r-select__sep {
flex: 0 0 auto;
}
.r-select__title,
.r-select__placeholder {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Flex items default to `min-width: auto` — without this the title
refuses to shrink and a long selection clips instead of ellipsizing. */
.r-select__title {
min-width: 0;
}
.r-select__placeholder {
color: var(--r-color-fg-faint);
}

View File

@@ -300,7 +300,10 @@ function clear() {
}
onMounted(() => {
if (props.autofocus) inputRef.value?.focus();
// `preventScroll` because an autofocused field often lives in a panel
// that a positioner (floating-ui) only places after mount — letting the
// UA scroll to its pre-placement box would yank the page.
if (props.autofocus) inputRef.value?.focus({ preventScroll: true });
});
// Slot shape helpers — drives whether to render the prepend / append