Why don't Items have an onAction
event?
#5058
Replies: 2 comments 9 replies
-
There are multiple ways to potentially trigger or not trigger an In addition, collections also respond to different events following aria patterns and, absent that, native examples. So menu items for keyboard actually call |
Beta Was this translation helpful? Give feedback.
-
hey @snowystinger I'm writing in a new comment because in the comment thread above I mixed up some things and there were others that I didn't understand well. I've been thinking about this and I think I've come up with a better way to solve these problems: Problems
Solution:For each state of an item (selected, collapsed, etc.), a setter and a getter that receive the item should be exposed. Taking the case of selection as an example, if you think about it actually // replace this (current API)
type CollectionProps = {
defaultSelectedKeys: 'all' | Iterable<Key>, // initial state
selectedKeys: 'all' | Iterable<Key>, // current state
onSelectionChange: (keys: Selection) => any, // setter
onAction: (key: Key) => void,
}
// with this (new API)
type CollectionProps = {
getSelected: (item: object) => boolean, // getter
setSelected: (item: object) => void, // setter
getAction: (item: object) => () => void, // getter
} The solution that I proposed before (in the thread above) was to move the handling of actions or selection, from the collections to the items.
|
Beta Was this translation helpful? Give feedback.
-
Context: the menu component has an event called
onAction
that receives thekey
of the pressed item as a parameter (source).This seems unnecessarily complicated because a relationship must be maintained between the event and the keys.
I see there is work being done on allowing href. But better yet,
Why not provide an
onPress
event on each item instead? EDIT:onAction
, notonPress
.Beta Was this translation helpful? Give feedback.
All reactions