@react-aria/tag 3.0.0-nightly.3180 → 3.0.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 +437 -0
- package/dist/main.js +271 -190
- package/dist/main.js.map +1 -1
- package/dist/module.js +273 -179
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +53 -26
- package/dist/types.d.ts.map +1 -1
- package/package.json +18 -12
- package/src/index.ts +5 -3
- package/src/useTag.ts +70 -59
- package/src/useTagGroup.ts +79 -20
- package/src/TagKeyboardDelegate.ts +0 -91
|
@@ -1,91 +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 {GridCollection} from '@react-types/grid';
|
|
14
|
-
import {GridKeyboardDelegate} from '@react-aria/grid';
|
|
15
|
-
import {Key} from 'react';
|
|
16
|
-
|
|
17
|
-
export class TagKeyboardDelegate<T> extends GridKeyboardDelegate<T, GridCollection<T>> {
|
|
18
|
-
getKeyRightOf(key: Key) {
|
|
19
|
-
return this.direction === 'rtl' ? this.getKeyAbove(key) : this.getKeyBelow(key);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
getKeyLeftOf(key: Key) {
|
|
23
|
-
return this.direction === 'rtl' ? this.getKeyBelow(key) : this.getKeyAbove(key);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getKeyBelow(key) {
|
|
27
|
-
let startItem = this.collection.getItem(key);
|
|
28
|
-
if (!startItem) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// If focus was on a cell, start searching from the parent row
|
|
33
|
-
if (this.isCell(startItem)) {
|
|
34
|
-
key = startItem.parentKey;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Find the next item
|
|
38
|
-
key = this.findNextKey(key);
|
|
39
|
-
if (key != null) {
|
|
40
|
-
// If focus was on a cell, focus the cell with the same index in the next row.
|
|
41
|
-
if (this.isCell(startItem)) {
|
|
42
|
-
let item = this.collection.getItem(key);
|
|
43
|
-
let newKey = [...item.childNodes][startItem.index].key;
|
|
44
|
-
|
|
45
|
-
// Ignore disabled tags
|
|
46
|
-
if (this.disabledKeys.has(newKey)) {
|
|
47
|
-
return this.getKeyBelow(newKey);
|
|
48
|
-
}
|
|
49
|
-
return newKey;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Otherwise, focus the next row
|
|
53
|
-
if (this.focusMode === 'row') {
|
|
54
|
-
return key;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
getKeyAbove(key) {
|
|
60
|
-
let startItem = this.collection.getItem(key);
|
|
61
|
-
if (!startItem) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// If focus is on a cell, start searching from the parent row
|
|
66
|
-
if (this.isCell(startItem)) {
|
|
67
|
-
key = startItem.parentKey;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Find the previous item
|
|
71
|
-
key = this.findPreviousKey(key);
|
|
72
|
-
if (key != null) {
|
|
73
|
-
// If focus was on a cell, focus the cell with the same index in the previous row.
|
|
74
|
-
if (this.isCell(startItem)) {
|
|
75
|
-
let item = this.collection.getItem(key);
|
|
76
|
-
let newKey = [...item.childNodes][startItem.index].key;
|
|
77
|
-
|
|
78
|
-
// ignore disabled tags
|
|
79
|
-
if (this.disabledKeys.has(newKey)) {
|
|
80
|
-
return this.getKeyAbove(newKey);
|
|
81
|
-
}
|
|
82
|
-
return newKey;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Otherwise, focus the previous row
|
|
86
|
-
if (this.focusMode === 'row') {
|
|
87
|
-
return key;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|