Я должен обрабатывать щелчок или изменение внутренних элементов в переключателе ( ChoiceGroup ) в office-ui-fabri c -реагировать. В приведенном ниже примере я хочу нажать на ссылку, но не могу. Насколько я понимаю, мы можем отобразить элемент JSX внутри onRenderField опции (типа IChoiceGroupOption). Я могу сделать правильно, но не могу выполнить никаких действий по этому поводу. Нужно ли отменять щелчок переключателя? Как?
const {
ChoiceGroup,
IChoiceGroupOption,
mergeStyles,
Fabric
} = window.Fabric;
const ChoiceGroupCustomExample: React.FunctionComponent = () => {
return (
<ChoiceGroup defaultSelectedKey="B" options={options} label="Pick one" />
);
};
const optionRootClass = mergeStyles({
display: "flex",
flexDirection: "column",
alignItems: "baseline"
});
const options: IChoiceGroupOption[] = [
{
key: "A",
text: "Option A",
ariaLabel:
"Mark displayed items as read after - Press tab for further action",
onRenderField: (props, render) => {
return (
<div className={optionRootClass}>
{render!(props)}
<a
href="#"
onClick={() => console.log("SSSSSSSSSSSS")}
style={{ marginLeft: "25px" }}
>
SHUBHAW KUMAR
</a>
</div>
);
}
},
{ key: "B", text: "Option B" },
{ key: "C", text: "Option C", disabled: true },
{ key: "D", text: "Option D" }
];
const ChoiceGroupCustomExampleWrapper = () => (
<Fabric>
<ChoiceGroupCustomExample />
</Fabric>
);
ReactDOM.render(
<ChoiceGroupCustomExampleWrapper />,
document.getElementById("content")
);
<script src="//unpkg.com/office-ui-fabric-react@7/dist/office-ui-fabric-react.js"></script>
<script src="//unpkg.com/@uifabric/react-hooks@7/dist/react-hooks.js"></script>
<div id="content"></div>
Вы можете найти код на этом codepen .