@startsimpli/ui-native 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/__tests__/tabbar.test.tsx +21 -0
- package/src/components/TabBar.tsx +1 -1
- package/src/styles.ts +3 -0
package/package.json
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { TabBar } from '../components/TabBar';
|
|
3
|
+
import { flat, render } from '../../test/render';
|
|
4
|
+
|
|
5
|
+
describe('TabBar labels never wrap or clip', () => {
|
|
6
|
+
const items = ['Home', 'GO', 'Notes', 'To-dos', 'Connections'].map((label) => ({ key: label, label }));
|
|
7
|
+
const r = render(<TabBar items={items} activeKey="Home" onChange={() => {}} />);
|
|
8
|
+
it('every label is one line that truncates with an ellipsis', () => {
|
|
9
|
+
const labels = r.root.findAll((n) => n.type === 'Text');
|
|
10
|
+
expect(labels).toHaveLength(5);
|
|
11
|
+
for (const l of labels) {
|
|
12
|
+
expect(l.props.numberOfLines).toBe(1);
|
|
13
|
+
expect(l.props.ellipsizeMode).toBe('tail');
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
it('items can shrink below their label width so the ellipsis can happen', () => {
|
|
17
|
+
for (const tab of r.root.findAll((n) => n.props.accessibilityRole === 'tab')) {
|
|
18
|
+
expect(flat(tab.props.style).minWidth).toBe(0);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -41,7 +41,7 @@ export function TabBar({ items, activeKey, onChange, style }: TabBarProps) {
|
|
|
41
41
|
style={tabItemStyle(theme)}
|
|
42
42
|
>
|
|
43
43
|
{item.icon?.({ active, color })}
|
|
44
|
-
<RNText style={tabLabelStyle(theme, active)}>{item.label}</RNText>
|
|
44
|
+
<RNText numberOfLines={1} ellipsizeMode="tail" style={tabLabelStyle(theme, active)}>{item.label}</RNText>
|
|
45
45
|
</Pressable>
|
|
46
46
|
);
|
|
47
47
|
})}
|
package/src/styles.ts
CHANGED
|
@@ -467,6 +467,9 @@ export function tabItemStyle(theme: Theme): ViewStyle {
|
|
|
467
467
|
justifyContent: 'center',
|
|
468
468
|
gap: 2,
|
|
469
469
|
paddingVertical: theme.spacing.xs,
|
|
470
|
+
// Lets a long label shrink to the slot and ellipsize instead of widening it.
|
|
471
|
+
minWidth: 0,
|
|
472
|
+
paddingHorizontal: 2,
|
|
470
473
|
};
|
|
471
474
|
}
|
|
472
475
|
|