Shopify Polaris:如何使ActionList中的项目活跃?
我有一个具有一些内容的动作清单。 我想使活动活动:单击项目时为TRUE。 我正在努力使用Shopify Polaris的动作清单来做到这一点。 我可以得到我点击的索引。但是我不确定如何将索引使用到Active:true和在哪里。 如果您能给我一些建议,那确实对我有帮助。
import React, { useCallback, useState } from "react";
import { ActionList, Button, Icon, Popover } from "@shopify/polaris";
import { TickSmallMinor, ImportMinor } from "@shopify/polaris-icons";
const actions = [
{
content: "Import file"
},
{
content: "Export file"
},
{
content: "Export file2"
},
{
content: "Export file3"
},
{
content: "Export file4"
}
];
export default function ActionListWithSuffixExample() {
const [active, setActive] = useState(true);
const [isClicked, setIsClicked] = useState(Array(actions.length).fill(false));
console.log(actions.length);
const toggleActive = useCallback(() => setActive((active) => !active), []);
const activator = (
<Button onClick={toggleActive} disclosure>
More actions
</Button>
);
const handleClick = (index) => {
console.log("index", index);
setIsClicked((prev) => [
...prev.slice(0, index),
!prev[index],
...prev.slice(index + 1)
]);
};
return (
<div style={{ height: "200px" }}>
<Popover
active={active}
activator={activator}
autofocusTarget="first-node"
onClose={toggleActive}
>
<ActionList
actionRole="menuitem"
items={actions.map((a, i) => ({
onAction: () => handleClick(i),
active: isClicked,
content: a.content,
icon: ImportMinor,
suffix: <Icon source={TickSmallMinor} />
}))}
/>
</Popover>
</div>
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您忘了将索引放在活动属性中
You forgot to put the index in the active property