diff --git a/change/@fluentui-react-toolbar-bac826cc-5a66-447f-ab37-f85d8df68fb9.json b/change/@fluentui-react-toolbar-bac826cc-5a66-447f-ab37-f85d8df68fb9.json new file mode 100644 index 00000000000000..5d22ae19dc7070 --- /dev/null +++ b/change/@fluentui-react-toolbar-bac826cc-5a66-447f-ab37-f85d8df68fb9.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "fix: ToolbarRadio example and click", + "packageName": "@fluentui/react-toolbar", + "email": "chassunc@microsoft.com", + "dependentChangeType": "none" +} diff --git a/packages/react-components/react-toolbar/src/components/Toolbar/useToolbar.ts b/packages/react-components/react-toolbar/src/components/Toolbar/useToolbar.ts index 05dfaa620a01a3..d688508a5b8592 100644 --- a/packages/react-components/react-toolbar/src/components/Toolbar/useToolbar.ts +++ b/packages/react-components/react-toolbar/src/components/Toolbar/useToolbar.ts @@ -65,7 +65,7 @@ export const useToolbar_unstable = (props: ToolbarProps, ref: React.Ref { isConformant({ @@ -21,4 +23,49 @@ describe('ToolbarRadioButton', () => { ); expect(result.container).toMatchSnapshot(); }); + + it('should call onCheckedValueChange with proper value', () => { + const onCheckedValueChange = jest.fn(); + + const { getByText } = render( + + + italic + + + bold + + , + ); + + userEvent.click(getByText('bold')); + + expect(onCheckedValueChange).toHaveBeenCalledWith( + expect.objectContaining({ + type: 'click', + }), + expect.objectContaining({ + checkedItems: expect.arrayContaining(['bold']), + }), + ); + }); + + it('should check the proper value', () => { + const onCheckedValueChange = jest.fn(); + + const { getByText } = render( + + + italic + + + bold + + , + ); + + userEvent.click(getByText('bold')); + + expect(getByText('bold').getAttribute('aria-pressed')).toBe('true'); + }); }); diff --git a/packages/react-components/react-toolbar/src/components/ToolbarRadioButton/useToolbarRadioButton.ts b/packages/react-components/react-toolbar/src/components/ToolbarRadioButton/useToolbarRadioButton.ts index 6d8aaf079088dc..1bed8249f40d85 100644 --- a/packages/react-components/react-toolbar/src/components/ToolbarRadioButton/useToolbarRadioButton.ts +++ b/packages/react-components/react-toolbar/src/components/ToolbarRadioButton/useToolbarRadioButton.ts @@ -28,10 +28,6 @@ export const useToolbarRadioButton_unstable = ( const handleOnClick = useEventCallback( (e: React.MouseEvent & React.MouseEvent) => { - e.preventDefault(); - e.stopPropagation(); - return; - handleRadio?.(e, state.name, state.value, state.checked); onClickOriginal?.(e); }, diff --git a/packages/react-components/react-toolbar/src/stories/Toolbar/ToolbarRadioControlled.stories.tsx b/packages/react-components/react-toolbar/src/stories/Toolbar/ToolbarRadioControlled.stories.tsx index 61dbfa07e7dbc3..587f4d8f697bd8 100644 --- a/packages/react-components/react-toolbar/src/stories/Toolbar/ToolbarRadioControlled.stories.tsx +++ b/packages/react-components/react-toolbar/src/stories/Toolbar/ToolbarRadioControlled.stories.tsx @@ -1,12 +1,13 @@ import * as React from 'react'; import { TextBold24Regular, TextItalic24Regular, TextUnderline24Regular } from '@fluentui/react-icons'; -import { Toolbar, ToolbarRadioButton, ToolbarDivider } from '@fluentui/react-toolbar'; +import { Toolbar, ToolbarRadioButton } from '@fluentui/react-toolbar'; import type { ToolbarProps } from '@fluentui/react-toolbar'; export const ControlledRadio = (props: Partial) => { const [checkedValues, setCheckedValues] = React.useState>({ - edit: ['cut', 'paste'], + edit: ['italic', 'bold'], }); + const onChange: ToolbarProps['onCheckedValueChange'] = (e, { name, checkedItems }) => { setCheckedValues(s => { return s ? { ...s, [name]: checkedItems } : { [name]: checkedItems }; @@ -18,7 +19,6 @@ export const ControlledRadio = (props: Partial) => { } /> } /> } /> - ); };