From 53183d374cfbdebc25a2a11f12ca607347bc61e2 Mon Sep 17 00:00:00 2001 From: Yif <877193178@qq.com> Date: Fri, 6 Nov 2026 17:53:01 +0800 Subject: [PATCH] fix(ui): keep effort tag edge clicks out of the slider --- apps/web/tests/declared-reasoning.e2e.ts | 19 +++++++++++ .../src/client/EffortSlider.module.css | 32 ++++++++++--------- .../tests/effort-tag-drag.client.spec.tsx | 3 +- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/apps/web/tests/declared-reasoning.e2e.ts b/apps/web/tests/declared-reasoning.e2e.ts index 4b804893b0..ebba03e46f 100644 --- a/apps/web/tests/declared-reasoning.e2e.ts +++ b/apps/web/tests/declared-reasoning.e2e.ts @@ -245,6 +245,25 @@ describe.skipIf(MODE === 'record').each([ const defaultHeight = await menu.evaluate(element => element.getBoundingClientRect().height) await menu.locator('[data-effort-label]').click() expect(await slider.inputValue()).toBe('0') + const tagHit = await menu.locator('[data-effort-tag]').evaluate((tag) => { + const caption = tag.querySelector('[data-effort-caption]')! + const bounds = tag.getBoundingClientRect() + const x = bounds.left + bounds.width / 2 + const y = bounds.bottom - 1 + return { + x, y, hitsCaption: document.elementFromPoint(x, y) === caption, + tagScrollWidth: tag.scrollWidth, tagClientWidth: tag.clientWidth, + captionScrollWidth: caption.scrollWidth, captionClientWidth: caption.clientWidth, + } + }) + expect(tagHit.hitsCaption).toBe(true) + await trigger.focus() + await page.mouse.click(tagHit.x, tagHit.y) + expect(await slider.inputValue()).toBe('0') + expect(await slider.evaluate(element => element === document.activeElement)).toBe(true) + expect(requests).toBe(0) + expect(tagHit.tagScrollWidth).toBe(tagHit.tagClientWidth) + expect(tagHit.captionScrollWidth).toBe(tagHit.captionClientWidth) await info.click() const tooltip = page.getByRole('tooltip') await tooltip.waitFor() diff --git a/packages/client/ui-model-selection/src/client/EffortSlider.module.css b/packages/client/ui-model-selection/src/client/EffortSlider.module.css index b3b6e82a06..872b22df55 100644 --- a/packages/client/ui-model-selection/src/client/EffortSlider.module.css +++ b/packages/client/ui-model-selection/src/client/EffortSlider.module.css @@ -20,12 +20,15 @@ grid-row: 2; container-type: inline-size; position: relative; + z-index: 1; + pointer-events: none; height: 28px; margin: 8px 8px 0; } .value { position: absolute; + pointer-events: auto; top: 0; left: 0; width: max-content; @@ -33,15 +36,9 @@ translate: clamp(0px, calc(var(--effort-thumb-size) / 2 + (100cqw - var(--effort-thumb-size)) * var(--dsh-effort-position) - 50%), calc(100cqw - 100%)) 0; display: inline-flex; align-items: center; - gap: 4px; box-sizing: border-box; max-width: 100%; height: 28px; - padding: 1px 8px; - border: 1px solid color-mix(in srgb, var(--dsw-alias-state-business-primary) 45%, transparent); - border-radius: 999px; - corner-shape: round; - background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 8%, var(--dsw-alias-bg-module-platform)); color: var(--dsw-alias-state-business-primary); font-size: 13px; line-height: 18px; @@ -53,20 +50,23 @@ user-select: none; } -.value:has(.infoButton) { - gap: 2px; - padding-inline-end: 1px; +.value:has(.infoButton) .caption { + padding-inline-end: 27px; } .caption { display: flex; flex: 1 1 auto; align-items: center; + box-sizing: border-box; min-width: 0; - height: 24px; - padding: 0; - border: 0; - background: transparent; + width: 100%; + height: 28px; + padding: 1px 8px; + border: 1px solid color-mix(in srgb, var(--dsw-alias-state-business-primary) 45%, transparent); + border-radius: 999px; + corner-shape: round; + background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 8%, var(--dsw-alias-bg-module-platform)); color: inherit; font: inherit; white-space: inherit; @@ -79,7 +79,6 @@ .caption:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; - border-radius: var(--dsw-radius-sm); } .caption[aria-disabled='true'] { @@ -113,8 +112,11 @@ } .infoButton { + position: absolute; + top: 2px; + right: 2px; + z-index: 1; display: inline-flex; - flex: 0 0 24px; align-items: center; justify-content: center; width: 24px; diff --git a/packages/client/ui-model-selection/tests/effort-tag-drag.client.spec.tsx b/packages/client/ui-model-selection/tests/effort-tag-drag.client.spec.tsx index 345d4bae3f..b39a361555 100644 --- a/packages/client/ui-model-selection/tests/effort-tag-drag.client.spec.tsx +++ b/packages/client/ui-model-selection/tests/effort-tag-drag.client.spec.tsx @@ -1,11 +1,12 @@ // @vitest-environment jsdom import { cleanup, fireEvent, render, screen } from '@testing-library/react' import { afterEach, expect, it, vi } from 'vitest' +import type { ComponentProps } from 'react' import { EffortSlider, type EffortSliderProps } from '../src/client/EffortSlider.tsx' afterEach(() => { cleanup(); vi.restoreAllMocks(); vi.unstubAllGlobals() }) -function setup(value: string | null = 'off', includeDefault = false, parentKey?: ReturnType) { +function setup(value: string | null = 'off', includeDefault = false, parentKey?: ComponentProps<'div'>['onKeyDown']) { vi.stubGlobal('matchMedia', (query: string) => ({ matches: query.includes('hover: hover'), media: query, onchange: null, addEventListener: vi.fn(), removeEventListener: vi.fn(), addListener: vi.fn(), removeListener: vi.fn(), dispatchEvent: () => true,