-
Notifications
You must be signed in to change notification settings - Fork 300
feat(Tabs): V16适配 #3534
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
Open
kaxium
wants to merge
11
commits into
jdf2e:feat_v4.x
Choose a base branch
from
kaxium:feat/v16-tabs
base: feat_v4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(Tabs): V16适配 #3534
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2c66912
style(tabs): 更新选项卡组件的样式和文档,添加字体相关变量
kaxium ccb8d02
style(tabs): 按钮类型更新相关样式和文档
kaxium 6be3d9b
feat(tabs): 添加自定义标签栏示例及辅助信息; 解决自定义title,点击不能滑动问题;
kaxium 645a0ec
chore(tabs): 启用 v16 版本支持
kaxium 6038957
style(tabs): 更新卡片模式样式
kaxium 750042d
style(tabs): 调整选项卡标题的内边距,优化边缘留白
kaxium 11b4f68
style(tabs): 更新选项卡标题的字体粗细为400
kaxium 3ae1c70
chore(tabs): 添加左对齐辅助操作示例及文档更新
kaxium 983094b
feat(tabs): 添加卡片模式下标题栏可滑动的支持及样式调整
kaxium fd0fccf
refactor(tabs): 移除不必要的背景图和样式调整
kaxium 8bb2ac5
feat(tabs): 更新选项卡标题样式,支持动态缩放和背景色调整
kaxium 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 |
|---|---|---|
|
|
@@ -480,7 +480,7 @@ | |
| "v15": 2, | ||
| "author": "oasis", | ||
| "dd": true, | ||
| "v16": false | ||
| "v16": true | ||
| } | ||
| ] | ||
| }, | ||
|
|
||
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
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
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
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
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
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,59 @@ | ||
| import React, { useState } from 'react' | ||
| import { Tabs } from '@nutui/nutui-react' | ||
|
|
||
| const Demo24 = () => { | ||
| const [tabvalue, setTabvalue] = useState('c1') | ||
| const list = [ | ||
| { title: '选中态标题', subtitle: '辅助信息文本', paneKey: 'c1' }, | ||
| { title: '非选中态标题', subtitle: '辅助信息文本', paneKey: 'c2' }, | ||
| { title: '非选中态标题', subtitle: '辅助信息文本', paneKey: 'c3' }, | ||
| { title: '非选中态标题', subtitle: '辅助信息文本', paneKey: 'c4' }, | ||
| ] | ||
| return ( | ||
| <Tabs | ||
| value={tabvalue} | ||
| style={{ | ||
| '--nutui-tabs-titles-height': 'calc(44px * var(--nut-scale-f, 1))', | ||
| }} | ||
| title={() => { | ||
| return list.map((item) => { | ||
| const active = tabvalue === item.paneKey | ||
| return ( | ||
| <div | ||
| key={item.paneKey} | ||
| onClick={() => setTabvalue(item.paneKey)} | ||
| className={`nut-tabs-titles-item ${active ? 'nut-tabs-titles-item-active' : ''}`} | ||
| style={{ | ||
| flexDirection: 'column', | ||
| justifyContent: 'center', | ||
| lineHeight: 'initial', | ||
| }} | ||
| > | ||
| <span className="nut-tabs-titles-item-text">{item.title}</span> | ||
| <span | ||
| style={{ | ||
| textAlign: 'center', | ||
| fontSize: 'calc(11px * var(--nut-scale-font, 1))', | ||
| fontWeight: '400', | ||
| lineHeight: 'calc(16px * var(--nut-scale-font, 1))', | ||
| color: active | ||
| ? 'var(--nutui-tabs-titles-item-active-color, #ff0f23)' | ||
| : 'var(--nutui-color-text, #505259)', | ||
| }} | ||
| > | ||
| {item.subtitle} | ||
| </span> | ||
| </div> | ||
| ) | ||
| }) | ||
| }} | ||
| > | ||
| {list.map((item) => ( | ||
| <Tabs.TabPane key={item.paneKey} value={item.paneKey}> | ||
| {item.title} | ||
| </Tabs.TabPane> | ||
| ))} | ||
| </Tabs> | ||
| ) | ||
| } | ||
| export default Demo24 | ||
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,101 @@ | ||
| import React, { useState } from 'react' | ||
| import { Tabs } from '@nutui/nutui-react' | ||
| import { Search } from '@nutui/icons-react' | ||
|
|
||
| const Demo25 = () => { | ||
| const [tabvalue, setTabvalue] = useState('c1') | ||
| const list = [ | ||
| { title: 'Tab longitem 1', paneKey: 'c1' }, | ||
| { title: 'Tab longitem 2', paneKey: 'c2' }, | ||
| { title: 'Tab3', paneKey: 'c3' }, | ||
| { title: 'Tab4', paneKey: 'c4' }, | ||
| { title: 'Tab5', paneKey: 'c5' }, | ||
| { title: 'Tab6', paneKey: 'c6' }, | ||
| ] | ||
|
|
||
| const renderTitles = () => { | ||
| const items = list.map((item) => { | ||
| const active = tabvalue === item.paneKey | ||
| return ( | ||
| <div | ||
| key={item.paneKey} | ||
| onClick={() => setTabvalue(item.paneKey)} | ||
| className={`nut-tabs-titles-item ${active ? 'nut-tabs-titles-item-active' : ''}`} | ||
| > | ||
| <span className="nut-tabs-titles-item-text">{item.title}</span> | ||
| <span className="nut-tabs-titles-item-line" /> | ||
| </div> | ||
| ) | ||
| }) | ||
| // 末尾占位:预留 >= 辅助操作宽度的空白,滚到最右端时末项文字不被辅助操作遮挡 | ||
| items.push( | ||
| <div | ||
| className="nut-tabs-titles-item" | ||
| key="__aux_placeholder__" | ||
| aria-hidden | ||
| style={{ flex: 'none', minWidth: 'calc(36px * var(--nut-scale-f, 1))' }} | ||
| /> | ||
| ) | ||
| return items | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| style={{ | ||
| position: 'relative', | ||
| }} | ||
| > | ||
| <Tabs | ||
| value={tabvalue} | ||
| align="left" | ||
| title={renderTitles} | ||
| style={{ | ||
| '--nutui-tabs-titles-background-color': | ||
| 'var(--nutui-color-background, #f2f3f5)', | ||
| }} | ||
| > | ||
| {list.map((item) => ( | ||
| <Tabs.TabPane key={item.paneKey} value={item.paneKey}> | ||
| {item.title} | ||
| </Tabs.TabPane> | ||
| ))} | ||
| </Tabs> | ||
| <div | ||
| style={{ | ||
| position: 'absolute', | ||
| top: 0, | ||
| right: 0, | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| height: | ||
| 'var(--nutui-tabs-titles-height, calc(36px * var(--nut-scale-f, 1)))', | ||
| }} | ||
| > | ||
| <div | ||
| style={{ | ||
| width: 'calc(16px * var(--nut-scale-f, 1))', | ||
| height: '100%', | ||
| background: | ||
| 'linear-gradient(to left, var(--nutui-color-background, #f0f2f7) 0%, transparent 100%)', | ||
| }} | ||
| /> | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| height: '100%', | ||
| width: 'calc(36px * var(--nut-scale-f, 1))', | ||
| background: 'var(--nutui-color-background, #f0f2f7)', | ||
| }} | ||
| > | ||
| <Search | ||
| width="calc(18px * var(--nut-scale-icon, 1))" | ||
| height="calc(18px * var(--nut-scale-icon, 1))" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
| export default Demo25 |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: jdf2e/nutui-react
Length of output: 29135
由 Tabs 组件统一提供自定义标题的可访问语义。
Tabs会直接将title()的返回值插入标题容器,不会为自定义节点补充tablist、tab、tabIndex、键盘处理、aria-selected、aria-controls或面板关联。因此,demo24 和 demo25 中仅绑定onClick的<div>无法通过键盘获得焦点和激活,辅助技术也无法读取标签状态或关联面板。请在
Tabs的标题渲染 API 中统一实现这些语义,并让两个演示使用该 API。不要在每个演示中重复实现 tabs 状态和键盘逻辑。src/packages/tabs/demos/h5/demo24.tsx#L22-L22src/packages/tabs/demos/h5/demo25.tsx#L25-L25🤖 Prompt for AI Agents