@react-aria/tabs 3.11.1 → 3.12.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/dist/import.mjs +2 -6
- package/dist/main.js +4 -8
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -6
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +3 -0
- package/package.json +16 -18
- package/src/index.ts +3 -7
- package/dist/TabsKeyboardDelegate.main.js +0 -73
- package/dist/TabsKeyboardDelegate.main.js.map +0 -1
- package/dist/TabsKeyboardDelegate.mjs +0 -68
- package/dist/TabsKeyboardDelegate.module.js +0 -68
- package/dist/TabsKeyboardDelegate.module.js.map +0 -1
- package/dist/types.d.ts +0 -42
- package/dist/types.d.ts.map +0 -1
- package/dist/useTab.main.js +0 -68
- package/dist/useTab.main.js.map +0 -1
- package/dist/useTab.mjs +0 -63
- package/dist/useTab.module.js +0 -63
- package/dist/useTab.module.js.map +0 -1
- package/dist/useTabList.main.js +0 -67
- package/dist/useTabList.main.js.map +0 -1
- package/dist/useTabList.mjs +0 -62
- package/dist/useTabList.module.js +0 -62
- package/dist/useTabList.module.js.map +0 -1
- package/dist/useTabPanel.main.js +0 -47
- package/dist/useTabPanel.main.js.map +0 -1
- package/dist/useTabPanel.mjs +0 -42
- package/dist/useTabPanel.module.js +0 -42
- package/dist/useTabPanel.module.js.map +0 -1
- package/dist/utils.main.js +0 -29
- package/dist/utils.main.js.map +0 -1
- package/dist/utils.mjs +0 -23
- package/dist/utils.module.js +0 -23
- package/dist/utils.module.js.map +0 -1
- package/src/TabsKeyboardDelegate.ts +0 -98
- package/src/useTab.ts +0 -82
- package/src/useTabList.ts +0 -75
- package/src/useTabPanel.ts +0 -47
- package/src/utils.ts +0 -33
package/src/useTab.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {AriaTabProps} from '@react-types/tabs';
|
|
14
|
-
import {DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';
|
|
15
|
-
import {filterDOMProps, mergeProps, useLinkProps} from '@react-aria/utils';
|
|
16
|
-
import {generateId} from './utils';
|
|
17
|
-
import {TabListState} from '@react-stately/tabs';
|
|
18
|
-
import {useFocusable} from '@react-aria/focus';
|
|
19
|
-
import {useSelectableItem} from '@react-aria/selection';
|
|
20
|
-
|
|
21
|
-
export interface TabAria {
|
|
22
|
-
/** Props for the tab element. */
|
|
23
|
-
tabProps: DOMAttributes,
|
|
24
|
-
/** Whether the tab is currently selected. */
|
|
25
|
-
isSelected: boolean,
|
|
26
|
-
/** Whether the tab is disabled. */
|
|
27
|
-
isDisabled: boolean,
|
|
28
|
-
/** Whether the tab is currently in a pressed state. */
|
|
29
|
-
isPressed: boolean
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Provides the behavior and accessibility implementation for a tab.
|
|
34
|
-
* When selected, the associated tab panel is shown.
|
|
35
|
-
*/
|
|
36
|
-
export function useTab<T>(
|
|
37
|
-
props: AriaTabProps,
|
|
38
|
-
state: TabListState<T>,
|
|
39
|
-
ref: RefObject<FocusableElement | null>
|
|
40
|
-
): TabAria {
|
|
41
|
-
let {key, isDisabled: propsDisabled, shouldSelectOnPressUp} = props;
|
|
42
|
-
let {selectionManager: manager, selectedKey} = state;
|
|
43
|
-
|
|
44
|
-
let isSelected = key === selectedKey;
|
|
45
|
-
|
|
46
|
-
let isDisabled = propsDisabled || state.isDisabled || state.selectionManager.isDisabled(key);
|
|
47
|
-
let {itemProps, isPressed} = useSelectableItem({
|
|
48
|
-
selectionManager: manager,
|
|
49
|
-
key,
|
|
50
|
-
ref,
|
|
51
|
-
isDisabled,
|
|
52
|
-
shouldSelectOnPressUp,
|
|
53
|
-
linkBehavior: 'selection'
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
let tabId = generateId(state, key, 'tab');
|
|
57
|
-
let tabPanelId = generateId(state, key, 'tabpanel');
|
|
58
|
-
let {tabIndex} = itemProps;
|
|
59
|
-
|
|
60
|
-
let item = state.collection.getItem(key);
|
|
61
|
-
let domProps = filterDOMProps(item?.props, {labelable: true});
|
|
62
|
-
delete domProps.id;
|
|
63
|
-
let linkProps = useLinkProps(item?.props);
|
|
64
|
-
let {focusableProps} = useFocusable({
|
|
65
|
-
...item?.props,
|
|
66
|
-
isDisabled
|
|
67
|
-
}, ref);
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
tabProps: mergeProps(domProps, focusableProps, linkProps, itemProps, {
|
|
71
|
-
id: tabId,
|
|
72
|
-
'aria-selected': isSelected,
|
|
73
|
-
'aria-disabled': isDisabled || undefined,
|
|
74
|
-
'aria-controls': isSelected ? tabPanelId : undefined,
|
|
75
|
-
tabIndex: isDisabled ? undefined : tabIndex,
|
|
76
|
-
role: 'tab'
|
|
77
|
-
}),
|
|
78
|
-
isSelected,
|
|
79
|
-
isDisabled,
|
|
80
|
-
isPressed
|
|
81
|
-
};
|
|
82
|
-
}
|
package/src/useTabList.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {AriaTabListProps} from '@react-types/tabs';
|
|
14
|
-
import {DOMAttributes, RefObject} from '@react-types/shared';
|
|
15
|
-
import {mergeProps, useId, useLabels} from '@react-aria/utils';
|
|
16
|
-
import {TabListState} from '@react-stately/tabs';
|
|
17
|
-
import {tabsIds} from './utils';
|
|
18
|
-
import {TabsKeyboardDelegate} from './TabsKeyboardDelegate';
|
|
19
|
-
import {useLocale} from '@react-aria/i18n';
|
|
20
|
-
import {useMemo} from 'react';
|
|
21
|
-
import {useSelectableCollection} from '@react-aria/selection';
|
|
22
|
-
|
|
23
|
-
export interface AriaTabListOptions<T> extends Omit<AriaTabListProps<T>, 'children'> {}
|
|
24
|
-
|
|
25
|
-
export interface TabListAria {
|
|
26
|
-
/** Props for the tablist container. */
|
|
27
|
-
tabListProps: DOMAttributes
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Provides the behavior and accessibility implementation for a tab list.
|
|
32
|
-
* Tabs organize content into multiple sections and allow users to navigate between them.
|
|
33
|
-
*/
|
|
34
|
-
export function useTabList<T>(props: AriaTabListOptions<T>, state: TabListState<T>, ref: RefObject<HTMLElement | null>): TabListAria {
|
|
35
|
-
let {
|
|
36
|
-
orientation = 'horizontal',
|
|
37
|
-
keyboardActivation = 'automatic'
|
|
38
|
-
} = props;
|
|
39
|
-
let {
|
|
40
|
-
collection,
|
|
41
|
-
selectionManager: manager,
|
|
42
|
-
disabledKeys
|
|
43
|
-
} = state;
|
|
44
|
-
let {direction} = useLocale();
|
|
45
|
-
let delegate = useMemo(() => new TabsKeyboardDelegate(
|
|
46
|
-
collection,
|
|
47
|
-
direction,
|
|
48
|
-
orientation,
|
|
49
|
-
disabledKeys), [collection, disabledKeys, orientation, direction]);
|
|
50
|
-
|
|
51
|
-
let {collectionProps} = useSelectableCollection({
|
|
52
|
-
ref,
|
|
53
|
-
selectionManager: manager,
|
|
54
|
-
keyboardDelegate: delegate,
|
|
55
|
-
selectOnFocus: keyboardActivation === 'automatic',
|
|
56
|
-
disallowEmptySelection: true,
|
|
57
|
-
scrollRef: ref,
|
|
58
|
-
linkBehavior: 'selection'
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// Compute base id for all tabs
|
|
62
|
-
let tabsId = useId();
|
|
63
|
-
tabsIds.set(state, tabsId);
|
|
64
|
-
|
|
65
|
-
let tabListLabelProps = useLabels({...props, id: tabsId});
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
tabListProps: {
|
|
69
|
-
...mergeProps(collectionProps, tabListLabelProps),
|
|
70
|
-
role: 'tablist',
|
|
71
|
-
'aria-orientation': orientation,
|
|
72
|
-
tabIndex: undefined
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
package/src/useTabPanel.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {AriaTabPanelProps} from '@react-types/tabs';
|
|
14
|
-
import {DOMAttributes, RefObject} from '@react-types/shared';
|
|
15
|
-
import {generateId} from './utils';
|
|
16
|
-
import {mergeProps, useLabels} from '@react-aria/utils';
|
|
17
|
-
import {TabListState} from '@react-stately/tabs';
|
|
18
|
-
import {useHasTabbableChild} from '@react-aria/focus';
|
|
19
|
-
|
|
20
|
-
export interface TabPanelAria {
|
|
21
|
-
/** Props for the tab panel element. */
|
|
22
|
-
tabPanelProps: DOMAttributes
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Provides the behavior and accessibility implementation for a tab panel. A tab panel is a container for
|
|
28
|
-
* the contents of a tab, and is shown when the tab is selected.
|
|
29
|
-
*/
|
|
30
|
-
export function useTabPanel<T>(props: AriaTabPanelProps, state: TabListState<T> | null, ref: RefObject<Element | null>): TabPanelAria {
|
|
31
|
-
// The tabpanel should have tabIndex=0 when there are no tabbable elements within it.
|
|
32
|
-
// Otherwise, tabbing from the focused tab should go directly to the first tabbable element
|
|
33
|
-
// within the tabpanel.
|
|
34
|
-
let tabIndex = useHasTabbableChild(ref) ? undefined : 0;
|
|
35
|
-
|
|
36
|
-
const id = generateId(state, props.id ?? state?.selectedKey, 'tabpanel');
|
|
37
|
-
const tabPanelProps = useLabels({...props, id, 'aria-labelledby': generateId(state, state?.selectedKey, 'tab')});
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
tabPanelProps: mergeProps(tabPanelProps, {
|
|
41
|
-
tabIndex,
|
|
42
|
-
role: 'tabpanel',
|
|
43
|
-
'aria-describedby': props['aria-describedby'],
|
|
44
|
-
'aria-details': props['aria-details']
|
|
45
|
-
})
|
|
46
|
-
};
|
|
47
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {Key} from '@react-types/shared';
|
|
14
|
-
import {TabListState} from '@react-stately/tabs';
|
|
15
|
-
|
|
16
|
-
export const tabsIds: WeakMap<TabListState<unknown>, string> = new WeakMap<TabListState<unknown>, string>();
|
|
17
|
-
|
|
18
|
-
export function generateId<T>(state: TabListState<T> | null, key: Key | null | undefined, role: string): string {
|
|
19
|
-
if (!state) {
|
|
20
|
-
// this case should only happen in the first render before the tabs are registered
|
|
21
|
-
return '';
|
|
22
|
-
}
|
|
23
|
-
if (typeof key === 'string') {
|
|
24
|
-
key = key.replace(/\s+/g, '');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let baseId = tabsIds.get(state);
|
|
28
|
-
if (process.env.NODE_ENV !== 'production' && !baseId) {
|
|
29
|
-
console.error('There is no tab id, please check if you have rendered the tab panel before the tab list.');
|
|
30
|
-
}
|
|
31
|
-
return `${baseId}-${role}-${key}`;
|
|
32
|
-
}
|
|
33
|
-
|