Repository navigation
fix(core): Tab paints the press for every pointer #8714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] TabList: a mouse or pen press on a tab paints the same press feedback a finger's does, and its release fades back to the tab's hover tint. | ||
|
|
||
| @cixzhang |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
packages/core/src/utils/pressEveryPointer.source-build.test.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file pressEveryPointer.source-build.test.mjs | ||
| * @input Uses Babel, the StyleX plugin as the package stylesheet compiles it, | ||
| * and the sources of the controls that paint the press on a descendant | ||
| * @output Verifies Tab paints the controller's press for every pointer, not | ||
| * only inside `@media (pointer: coarse)` | ||
| * @position Regression test for `spec:AST-094` FR43 (one press model for | ||
| * every pointer) in the compiled CSS of those modules | ||
| */ | ||
|
|
||
| import fs from 'node:fs/promises'; | ||
| import path from 'node:path'; | ||
| import {fileURLToPath} from 'node:url'; | ||
| import {transformAsync} from '@babel/core'; | ||
| import stylexBabelPlugin from '@stylexjs/babel-plugin'; | ||
| import {describe, expect, it} from 'vitest'; | ||
| import stylexResolution from '../../../../scripts/stylex-module-resolution.cjs'; | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| async function compiledCss(fileName) { | ||
| const file = path.join(__dirname, '..', fileName); | ||
| const result = await transformAsync(await fs.readFile(file, 'utf8'), { | ||
| babelrc: false, | ||
| configFile: false, | ||
| filename: file, | ||
| presets: [ | ||
| ['@babel/preset-typescript', {isTSX: true, allExtensions: true}], | ||
| ['@babel/preset-react', {runtime: 'automatic'}], | ||
| ], | ||
| plugins: [ | ||
| [ | ||
| stylexBabelPlugin, | ||
| { | ||
| dev: false, | ||
| runtimeInjection: false, | ||
| genConditionalClasses: true, | ||
| treeshakeCompensation: true, | ||
| unstable_moduleResolution: stylexResolution.stylexModuleResolution, | ||
| }, | ||
| ], | ||
| ], | ||
| }); | ||
| return stylexBabelPlugin.processStylexRules( | ||
| result?.metadata?.stylex ?? [], | ||
| false, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * The rules painting the press image on an arm, each with whether it sits | ||
| * inside `@media (pointer: coarse)`. | ||
| */ | ||
| function pressImageRules(css, arm) { | ||
| const out = []; | ||
| const media = /@media ([^{]+)\{((?:[^{}]*\{[^{}]*\})*)[^{}]*\}/g; | ||
| const coarseRanges = []; | ||
| for (const match of css.matchAll(media)) { | ||
| if (match[1].includes('pointer: coarse')) { | ||
| coarseRanges.push([match.index, match.index + match[0].length]); | ||
| } | ||
| } | ||
| for (const match of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) { | ||
| if ( | ||
| match[1].includes(`[data-astryx-press="${arm}"]`) && | ||
| /background-image:\s*var\(--_press-paint-image\)/.test(match[2]) | ||
| ) { | ||
| out.push({ | ||
| coarseOnly: coarseRanges.some( | ||
| ([from, to]) => match.index >= from && match.index < to, | ||
| ), | ||
| }); | ||
| } | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| const CONTROLS = ['TabList/Tab.tsx']; | ||
|
|
||
| describe('controls that paint the press on a descendant', () => { | ||
| for (const control of CONTROLS) { | ||
| it(`${control} paints both arms for every pointer, not only a coarse one`, async () => { | ||
| const css = await compiledCss(control); | ||
| for (const arm of ['on', 'fading']) { | ||
| const rules = pressImageRules(css, arm); | ||
| expect(rules.length, `${control} ${arm}`).toBeGreaterThan(0); | ||
| expect( | ||
| rules.some(rule => !rule.coarseOnly), | ||
| `${control} ${arm}`, | ||
| ).toBe(true); | ||
| } | ||
| }); | ||
| } | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: keying the
0son:hoveralso makes every mouse hover-in on a tab appear at once instead of easing over--duration-fast(the hover-out still eases). If that is intended, a line in the changeset would tell consumers; no current spec sets Tab's hover timing either way.