Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(web): expose SVG preview toggle state (#40332)

yyhcbd71699de5b
diff --git a/web/app/components/base/svg/__tests__/index.spec.tsx b/web/app/components/base/svg/__tests__/index.spec.tsx
index 71b4f565895..527cbc7a1cc 100644
--- a/web/app/components/base/svg/__tests__/index.spec.tsx
+++ b/web/app/components/base/svg/__tests__/index.spec.tsx
@@ -3,14 +3,18 @@ import userEvent from '@testing-library/user-event'
import SVGBtn from '..'
describe('SVGBtn', () => {
- it('toggles SVG mode when clicked', async () => {
+ it('exposes and toggles the SVG preview state', async () => {
const user = userEvent.setup()
const setIsSVG = vi.fn()
- render(<SVGBtn isSVG={false} setIsSVG={setIsSVG} />)
+ const { rerender } = render(<SVGBtn isSVG={false} setIsSVG={setIsSVG} />)
- await user.click(screen.getByRole('button'))
+ await user.click(screen.getByRole('button', { name: 'SVG', pressed: false }))
expect(setIsSVG).toHaveBeenCalledOnce()
expect(setIsSVG.mock.calls[0]![0](false)).toBe(true)
+
+ rerender(<SVGBtn isSVG setIsSVG={setIsSVG} />)
+
+ expect(screen.getByRole('button', { name: 'SVG', pressed: true })).toBeInTheDocument()
})
})
diff --git a/web/app/components/base/svg/index.tsx b/web/app/components/base/svg/index.tsx
index 70d412ac44b..5586a49b04a 100644
--- a/web/app/components/base/svg/index.tsx
+++ b/web/app/components/base/svg/index.tsx
@@ -11,11 +11,13 @@ type ISVGBtnProps = {
const SVGBtn = ({ isSVG, setIsSVG }: ISVGBtnProps) => {
return (
<ActionButton
+ aria-label="SVG"
+ aria-pressed={isSVG}
onClick={() => {
setIsSVG((prevIsSVG) => !prevIsSVG)
}}
>
- <div className={cn('size-4', isSVG ? s.svgIconed : s.svgIcon)}></div>
+ <span aria-hidden="true" className={cn('block size-4', isSVG ? s.svgIconed : s.svgIcon)} />
</ActionButton>
)
}