You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: pass clicked image index as current to PreviewGroup onOpenChange - #540
Image.PreviewGroup calls preview.onOpenChange(open, { current }). When a preview is opened by clicking an image, current was the index that was selected before the click, not the index of the image that was clicked.
<Image.PreviewGrouppreview={{ onOpenChange }}><Imagesrc="src1"/><Imagesrc="src2"/><Imagesrc="src3"/></Image.PreviewGroup>// click the third image: onOpenChange(true, { current: 0 }) // expected { current: 2 }
The click handler sets the new index with setCurrent(index) and then calls triggerShowPreview(true), which reads current from the render that is still the old one. triggerShowPreview now takes the new index as an optional second argument and passes it to onOpenChange; the click handler passes the index it just resolved. Calls without an index (closing the preview, or open controlled from outside) still report the current index as before.
Test: onOpenChange should receive clicked image index as current in tests/previewGroup.test.tsx clicks the third image (true, { current: 2 }), closes the preview (false, { current: 2 }) and then opens the second image (true, { current: 1 }). It fails on master (received current: 0 where 2 is expected) and passes now. npx rc-test passes (8 suites, 85 tests), tsc --noEmit is clean, Prettier is clean on the changed files, and ESLint reports the same 2 hook-dependency warnings in PreviewGroup.tsx as on master.
Opening an image preview now reports the clicked image's index to the open-change callback, and closing keeps the existing behavior. No merge-blocking risk is evident.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
标题“fix: pass clicked image index as current to PreviewGroup onOpenChange”描述了主要变更:点击图片打开预览时,onOpenChange 回调应收到被点击图片的索引。原始摘要显示 triggerShowPreview 新增可选索引参数,并从图片点击处传入该索引,同时新增测试覆盖该行为。标题与变更集直接相关,且具体说明了修复内容。
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Fix failing CI checks
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: ec6b9680-2e39-48ca-883f-639cbfbea44d
Commits
Reviewing files that changed from the base of the PR and between b1a0b0a and 3f5fb9b.
Files selected for processing: 2
src/PreviewGroup.tsx
tests/previewGroup.test.tsx
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
This branch has not been deployed
No deployments
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
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.
Image.PreviewGroupcallspreview.onOpenChange(open, { current }). When a preview is opened by clicking an image,currentwas the index that was selected before the click, not the index of the image that was clicked.The click handler sets the new index with
setCurrent(index)and then callstriggerShowPreview(true), which readscurrentfrom the render that is still the old one.triggerShowPreviewnow takes the new index as an optional second argument and passes it toonOpenChange; the click handler passes the index it just resolved. Calls without an index (closing the preview, oropencontrolled from outside) still report the current index as before.Test:
onOpenChange should receive clicked image index as currentintests/previewGroup.test.tsxclicks the third image (true, { current: 2 }), closes the preview (false, { current: 2 }) and then opens the second image (true, { current: 1 }). It fails onmaster(receivedcurrent: 0where2is expected) and passes now.npx rc-testpasses (8 suites, 85 tests),tsc --noEmitis clean, Prettier is clean on the changed files, and ESLint reports the same 2 hook-dependency warnings inPreviewGroup.tsxas onmaster.Summary by CodeRabbit