panelui-native 1.4.0 → 1.5.0
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/lib/module/components/bottom-sheet/index.js +5 -1
- package/lib/module/components/bottom-sheet/index.js.map +1 -1
- package/lib/module/components/calendar/index.js +2 -1
- package/lib/module/components/calendar/index.js.map +1 -1
- package/lib/module/components/select/index.js +44 -8
- package/lib/module/components/select/index.js.map +1 -1
- package/lib/module/components/tabs/index.js +10 -1
- package/lib/module/components/tabs/index.js.map +1 -1
- package/lib/module/components/time-picker/index.js +41 -7
- package/lib/module/components/time-picker/index.js.map +1 -1
- package/lib/typescript/src/components/bottom-sheet/index.d.ts.map +1 -1
- package/lib/typescript/src/components/calendar/index.d.ts.map +1 -1
- package/lib/typescript/src/components/select/index.d.ts +9 -1
- package/lib/typescript/src/components/select/index.d.ts.map +1 -1
- package/lib/typescript/src/components/tabs/index.d.ts.map +1 -1
- package/lib/typescript/src/components/time-picker/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/bottom-sheet/index.tsx +3 -0
- package/src/components/calendar/index.tsx +2 -1
- package/src/components/select/index.tsx +56 -6
- package/src/components/tabs/index.tsx +6 -0
- package/src/components/time-picker/index.tsx +51 -11
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
isValidElement,
|
|
41
41
|
useCallback,
|
|
42
42
|
useContext,
|
|
43
|
+
useEffect,
|
|
43
44
|
useMemo,
|
|
44
45
|
useRef,
|
|
45
46
|
useState,
|
|
@@ -47,6 +48,8 @@ import {
|
|
|
47
48
|
type ReactNode,
|
|
48
49
|
} from 'react';
|
|
49
50
|
import {
|
|
51
|
+
AccessibilityInfo,
|
|
52
|
+
Platform,
|
|
50
53
|
Pressable,
|
|
51
54
|
ScrollView,
|
|
52
55
|
useWindowDimensions,
|
|
@@ -233,7 +236,7 @@ function SelectItem({ value, label, disabled, className, labelClassName }: Selec
|
|
|
233
236
|
|
|
234
237
|
return (
|
|
235
238
|
<Pressable
|
|
236
|
-
accessibilityRole=
|
|
239
|
+
accessibilityRole={ITEM_ROLE}
|
|
237
240
|
accessibilityState={{ selected, disabled: !!disabled }}
|
|
238
241
|
disabled={disabled}
|
|
239
242
|
onPress={() => context.onSelect(value)}
|
|
@@ -523,12 +526,36 @@ export interface SelectProps {
|
|
|
523
526
|
* `wheel` is an always-visible rotor (iOS; falls back to `menu` elsewhere).
|
|
524
527
|
*/
|
|
525
528
|
nativeAppearance?: 'menu' | 'wheel';
|
|
529
|
+
/**
|
|
530
|
+
* The field's name, read by screen readers and matched by voice control —
|
|
531
|
+
* usually the text of the label above it, such as "Priority". The chosen
|
|
532
|
+
* option, or the placeholder, is still read after it as the value.
|
|
533
|
+
*/
|
|
534
|
+
accessibilityLabel?: string;
|
|
535
|
+
/** What opening the field does, when the name alone does not say. */
|
|
536
|
+
accessibilityHint?: string;
|
|
526
537
|
children: ReactNode;
|
|
527
538
|
}
|
|
528
539
|
|
|
529
540
|
/** Space kept between a floating list and the side of the screen. */
|
|
530
541
|
const OVERLAY_EDGE = 8;
|
|
531
542
|
|
|
543
|
+
/*
|
|
544
|
+
* iOS gives `combobox` and `menuitem` no VoiceOver trait at all, so the trigger
|
|
545
|
+
* and its options were read as static text. There they are buttons — the
|
|
546
|
+
* trigger keeps `expanded`, an option keeps `selected` — and Android, where
|
|
547
|
+
* TalkBack understands both roles, keeps them.
|
|
548
|
+
*/
|
|
549
|
+
const TRIGGER_ROLE = Platform.OS === 'ios' ? 'button' : 'combobox';
|
|
550
|
+
const ITEM_ROLE = Platform.OS === 'ios' ? 'button' : 'menuitem';
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* How long after closing before focus goes back to the trigger. Long enough for
|
|
554
|
+
* the sheet's exit to finish, since a screen reader moves focus away from a
|
|
555
|
+
* view that is still on screen and leaving.
|
|
556
|
+
*/
|
|
557
|
+
const FOCUS_RETURN_DELAY = 400;
|
|
558
|
+
|
|
532
559
|
/**
|
|
533
560
|
* Where a floating list starts. It lines up with the trigger, and moves left
|
|
534
561
|
* when a list wider than the trigger would run off the right of the screen.
|
|
@@ -565,6 +592,8 @@ function SelectRoot({
|
|
|
565
592
|
emptyMessage = 'No matches',
|
|
566
593
|
native,
|
|
567
594
|
nativeAppearance = 'menu',
|
|
595
|
+
accessibilityLabel,
|
|
596
|
+
accessibilityHint,
|
|
568
597
|
children,
|
|
569
598
|
}: SelectProps) {
|
|
570
599
|
const [open, setOpen] = useState(false);
|
|
@@ -618,6 +647,14 @@ function SelectRoot({
|
|
|
618
647
|
*/
|
|
619
648
|
const noMatches = filtered !== null && filtered.seen > 0 && filtered.kept.length === 0;
|
|
620
649
|
|
|
650
|
+
const focusTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
651
|
+
useEffect(
|
|
652
|
+
() => () => {
|
|
653
|
+
if (focusTimer.current !== null) clearTimeout(focusTimer.current);
|
|
654
|
+
},
|
|
655
|
+
[]
|
|
656
|
+
);
|
|
657
|
+
|
|
621
658
|
const close = useCallback(() => {
|
|
622
659
|
chevron.value = withTiming(0, { duration: 160 });
|
|
623
660
|
setOpen(false);
|
|
@@ -625,6 +662,14 @@ function SelectRoot({
|
|
|
625
662
|
// A filter left behind would be waiting the next time the list opens, with
|
|
626
663
|
// most of the options missing and no obvious reason why.
|
|
627
664
|
setQuery('');
|
|
665
|
+
// Put a screen reader back on the field it opened, rather than wherever
|
|
666
|
+
// focus lands once the options leave.
|
|
667
|
+
if (focusTimer.current !== null) clearTimeout(focusTimer.current);
|
|
668
|
+
focusTimer.current = setTimeout(() => {
|
|
669
|
+
focusTimer.current = null;
|
|
670
|
+
const node = triggerRef.current;
|
|
671
|
+
if (node) AccessibilityInfo.sendAccessibilityEvent(node, 'focus');
|
|
672
|
+
}, FOCUS_RETURN_DELAY);
|
|
628
673
|
}, [chevron, onOpenChange]);
|
|
629
674
|
|
|
630
675
|
// An open overlay list catches the Android back button, closing itself
|
|
@@ -705,13 +750,18 @@ function SelectRoot({
|
|
|
705
750
|
<Pressable
|
|
706
751
|
ref={triggerRef}
|
|
707
752
|
/*
|
|
708
|
-
* A
|
|
709
|
-
*
|
|
710
|
-
* on a role that can be expanded. Announced as "collapsed"/"expanded"
|
|
711
|
-
* rather than as a button whose state has nowhere to be read.
|
|
753
|
+
* A combobox where the platform reads one, a button with `expanded` on
|
|
754
|
+
* iOS, which has no trait for a combobox. See TRIGGER_ROLE.
|
|
712
755
|
*/
|
|
713
|
-
accessibilityRole=
|
|
756
|
+
accessibilityRole={TRIGGER_ROLE}
|
|
714
757
|
accessibilityState={{ disabled: !!disabled, expanded: open }}
|
|
758
|
+
accessibilityLabel={accessibilityLabel}
|
|
759
|
+
accessibilityHint={accessibilityHint}
|
|
760
|
+
// With a name of its own the trigger no longer reads its text, so the
|
|
761
|
+
// choice is handed over as the value instead.
|
|
762
|
+
accessibilityValue={
|
|
763
|
+
accessibilityLabel ? { text: selectedLabel ?? placeholder } : undefined
|
|
764
|
+
}
|
|
715
765
|
hitSlop={size === 'xs' ? XS_TRIGGER_HIT_SLOP : undefined}
|
|
716
766
|
disabled={disabled}
|
|
717
767
|
onPress={toggle}
|
|
@@ -76,6 +76,8 @@ import { webDeps } from '../../primitives/web-deps';
|
|
|
76
76
|
|
|
77
77
|
const SPRING = { damping: 24, stiffness: 300, mass: 0.7 } as const;
|
|
78
78
|
|
|
79
|
+
const SCROLLER_STYLE = { flexGrow: 0, flexShrink: 0 } as const;
|
|
80
|
+
|
|
79
81
|
/**
|
|
80
82
|
* How far sideways a finger must travel before the panel takes the gesture
|
|
81
83
|
* from whatever is scrolling above it, and how far up or down before it gives
|
|
@@ -942,6 +944,10 @@ function TabsList({
|
|
|
942
944
|
// The row measures itself, and the indicator is positioned against it,
|
|
943
945
|
// so the scroller must not stretch it to the viewport width.
|
|
944
946
|
contentContainerStyle={{ flexGrow: 0 }}
|
|
947
|
+
// A ScrollView grows and shrinks on its main axis by default, and in a
|
|
948
|
+
// column with a fixed height that means the bar takes a share of the free
|
|
949
|
+
// space from the panel below it. The bar is as tall as its triggers.
|
|
950
|
+
style={SCROLLER_STYLE}
|
|
945
951
|
onContentSizeChange={restore}
|
|
946
952
|
>
|
|
947
953
|
{scoped}
|
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
type ReactNode,
|
|
53
53
|
} from 'react';
|
|
54
54
|
import {
|
|
55
|
+
Pressable,
|
|
55
56
|
ScrollView,
|
|
56
57
|
View,
|
|
57
58
|
type AccessibilityActionEvent,
|
|
@@ -402,6 +403,21 @@ function Column<T>({
|
|
|
402
403
|
|
|
403
404
|
useEffect(() => cancelTimer, [cancelTimer]);
|
|
404
405
|
|
|
406
|
+
/*
|
|
407
|
+
* A row you can see is a row you can tap. Dragging is not something every
|
|
408
|
+
* pointer can do reliably — a tremor, a head pointer, a switch — and the
|
|
409
|
+
* neighbouring rows are the ones being compared against anyway. The column
|
|
410
|
+
* scrolls there through the same effect a controlled value change uses.
|
|
411
|
+
*/
|
|
412
|
+
const pick = useCallback(
|
|
413
|
+
(to: number) => {
|
|
414
|
+
if (disabled || moving.current || to === index) return;
|
|
415
|
+
selectionTick();
|
|
416
|
+
onIndexChange(to);
|
|
417
|
+
},
|
|
418
|
+
[disabled, index, onIndexChange]
|
|
419
|
+
);
|
|
420
|
+
|
|
405
421
|
const selectedItem = items[index];
|
|
406
422
|
|
|
407
423
|
const onAccessibilityAction = useCallback(
|
|
@@ -454,7 +470,7 @@ function Column<T>({
|
|
|
454
470
|
onAccessibilityAction={onAccessibilityAction}
|
|
455
471
|
>
|
|
456
472
|
{items.map((item, i) => (
|
|
457
|
-
<ColumnRow key={i} offset={offset} index={i} selected={i === index}>
|
|
473
|
+
<ColumnRow key={i} offset={offset} index={i} selected={i === index} onPick={pick}>
|
|
458
474
|
{label(item)}
|
|
459
475
|
</ColumnRow>
|
|
460
476
|
))}
|
|
@@ -473,11 +489,13 @@ function ColumnRow({
|
|
|
473
489
|
offset,
|
|
474
490
|
index,
|
|
475
491
|
selected,
|
|
492
|
+
onPick,
|
|
476
493
|
children,
|
|
477
494
|
}: {
|
|
478
495
|
offset: SharedValue<number>;
|
|
479
496
|
index: number;
|
|
480
497
|
selected: boolean;
|
|
498
|
+
onPick: (index: number) => void;
|
|
481
499
|
children: string;
|
|
482
500
|
}) {
|
|
483
501
|
const slots = timePickerVariants();
|
|
@@ -499,13 +517,20 @@ function ColumnRow({
|
|
|
499
517
|
});
|
|
500
518
|
|
|
501
519
|
return (
|
|
502
|
-
<Animated.View
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
520
|
+
<Animated.View style={[style, { height: ROW_HEIGHT }]}>
|
|
521
|
+
{/* Hidden from screen readers: the column is one adjustable control to
|
|
522
|
+
them, stepped with increment and decrement, not a list of buttons. */}
|
|
523
|
+
<Pressable
|
|
524
|
+
accessible={false}
|
|
525
|
+
importantForAccessibility="no"
|
|
526
|
+
onPress={() => onPick(index)}
|
|
527
|
+
className={slots.row()}
|
|
528
|
+
style={{ height: ROW_HEIGHT }}
|
|
529
|
+
>
|
|
530
|
+
<Text className={cn(slots.rowLabel(), selected && slots.rowLabelSelected())}>
|
|
531
|
+
{children}
|
|
532
|
+
</Text>
|
|
533
|
+
</Pressable>
|
|
509
534
|
</Animated.View>
|
|
510
535
|
);
|
|
511
536
|
}
|
|
@@ -958,6 +983,18 @@ function RulerFace({
|
|
|
958
983
|
|
|
959
984
|
useEffect(() => cancelTimer, [cancelTimer]);
|
|
960
985
|
|
|
986
|
+
// Tapping a tick picks it, for the same reason a wheel's rows can be tapped.
|
|
987
|
+
const pick = useCallback(
|
|
988
|
+
(to: number) => {
|
|
989
|
+
if (disabled || moving.current || to === index) return;
|
|
990
|
+
const time = times[to];
|
|
991
|
+
if (!time) return;
|
|
992
|
+
selectionTick();
|
|
993
|
+
onValueChange(time);
|
|
994
|
+
},
|
|
995
|
+
[disabled, index, onValueChange, times]
|
|
996
|
+
);
|
|
997
|
+
|
|
961
998
|
const stepsPerHour = Math.max(1, Math.round(60 / minuteStep));
|
|
962
999
|
|
|
963
1000
|
/*
|
|
@@ -1037,10 +1074,13 @@ function RulerFace({
|
|
|
1037
1074
|
{times.slice(window.start, window.end).map((_, offset) => {
|
|
1038
1075
|
const i = window.start + offset;
|
|
1039
1076
|
return (
|
|
1040
|
-
<
|
|
1077
|
+
<Pressable
|
|
1041
1078
|
key={i}
|
|
1079
|
+
accessible={false}
|
|
1080
|
+
importantForAccessibility="no"
|
|
1081
|
+
onPress={() => pick(i)}
|
|
1042
1082
|
style={{ width: TICK_SPACING }}
|
|
1043
|
-
className="items-center justify-center"
|
|
1083
|
+
className="h-14 items-center justify-center"
|
|
1044
1084
|
>
|
|
1045
1085
|
<View
|
|
1046
1086
|
className={cn(
|
|
@@ -1050,7 +1090,7 @@ function RulerFace({
|
|
|
1050
1090
|
i % stepsPerHour === 0 ? 'h-7 bg-muted-foreground' : 'h-4 bg-border'
|
|
1051
1091
|
)}
|
|
1052
1092
|
/>
|
|
1053
|
-
</
|
|
1093
|
+
</Pressable>
|
|
1054
1094
|
);
|
|
1055
1095
|
})}
|
|
1056
1096
|
<View style={{ width: (times.length - window.end) * TICK_SPACING }} />
|