Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app-layout/runtime-drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function mapRuntimeHeaderActionsToHeaderActions(
// eslint-disable-next-line no-restricted-syntax -- Runtime plugin API: property not in TS type
...('pressedIconSvg' in runtimeHeaderAction &&
runtimeHeaderAction.pressedIconSvg && {
iconSvg: convertRuntimeTriggerToReactNode(runtimeHeaderAction.pressedIconSvg),
pressedIconSvg: convertRuntimeTriggerToReactNode(runtimeHeaderAction.pressedIconSvg),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is funny

There is an existing test on pressed icon state, but because of a bug here, it incorrectly propagated pressedIconSvg as a normal iconSvg, making the test false positive

All fixed now

}),
};
});
Expand Down
60 changes: 60 additions & 0 deletions src/button-group/__tests__/button-group.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,63 @@ describe('ButtonGroup Style API', () => {
expect(getComputedStyle(itemElement).getPropertyValue(customCssProps.styleFocusRingBorderWidth)).toBe('2px');
});
});

test('icon-toggle-button maintains correct icon on state change', () => {
const { rerender, container } = render(
<ButtonGroup
variant="icon"
ariaLabel="Test"
items={[
{
type: 'icon-toggle-button',
id: 'test-toggle-state',
text: 'Toggle State',
pressed: false,
iconSvg: (
<svg className="default-icon" focusable="false" viewBox="0 0 16 16">
<circle cx="8" cy="8" r="7" />
</svg>
),
pressedIconSvg: (
<svg className="pressed-icon" focusable="false" viewBox="0 0 16 16">
<circle cx="8" cy="8" r="8" fill="currentColor" />
</svg>
),
},
]}
/>
);
const wrapper = createWrapper(container).findButtonGroup()!;

expect(wrapper.findToggleButtonById('test-toggle-state')!.find('.default-icon')).toBeTruthy();
expect(wrapper.findToggleButtonById('test-toggle-state')!.find('.pressed-icon')).toBeFalsy();

// Rerender with pressed state
rerender(
<ButtonGroup
variant="icon"
ariaLabel="Test"
items={[
{
type: 'icon-toggle-button',
id: 'test-toggle-state',
text: 'Toggle State',
pressed: true,
iconSvg: (
<svg className="default-icon" focusable="false" viewBox="0 0 16 16">
<circle cx="8" cy="8" r="7" />
</svg>
),
pressedIconSvg: (
<svg className="pressed-icon" focusable="false" viewBox="0 0 16 16">
<circle cx="8" cy="8" r="8" fill="currentColor" />
</svg>
),
},
]}
/>
);

expect(wrapper.findToggleButtonById('test-toggle-state')!.find('.default-icon')).toBeFalsy();
expect(wrapper.findToggleButtonById('test-toggle-state')!.find('.pressed-icon')).toBeTruthy();
});
2 changes: 1 addition & 1 deletion src/button-group/icon-toggle-button-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const IconToggleButtonItem = forwardRef(
iconSvg={item.iconSvg}
pressedIconName={hasIcon ? item.pressedIconName : 'close'}
pressedIconUrl={item.pressedIconUrl}
pressedIconSvg={item.pressedIconUrl}
pressedIconSvg={item.pressedIconSvg}
ariaLabel={item.text}
onChange={event => fireCancelableEvent(onItemClick, { id: item.id, pressed: event.detail.pressed })}
ref={ref}
Expand Down
Loading