Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vitepress will cause component styles to be lost #4447

Closed
4 tasks done
qianmoQ opened this issue Dec 27, 2024 · 17 comments
Closed
4 tasks done

vitepress will cause component styles to be lost #4447

qianmoQ opened this issue Dec 27, 2024 · 17 comments

Comments

@qianmoQ
Copy link

qianmoQ commented Dec 27, 2024

Describe the bug

My calling method is

::: raw

<CodeRunner title="Disabled">
    <ShadcnInput placeholder="Input" v-model="input" disabled />
</CodeRunner>

:::

The expected rendering result is

image

The result of rendering in vitepress is

image

Causes disabled styles to be lost

Reproduction

The component reference address that caused the problem
https://view-shadcn-ui.devlive.org/components/form/input.html#disabled

Expected behavior

None

System Info

None

Additional context

No response

Validations

@qianmoQ qianmoQ added the bug: pending triage Maybe a bug, waiting for confirmation label Dec 27, 2024
@brc-dd
Copy link
Member

brc-dd commented Dec 30, 2024

Have you added the postcss plugin to handle ::raw? https://vitepress.dev/guide/markdown#raw

@brc-dd brc-dd added need more info Further information is requested and removed bug: pending triage Maybe a bug, waiting for confirmation labels Dec 30, 2024
@qianmoQ
Copy link
Author

qianmoQ commented Dec 30, 2024

Have you added the postcss plugin to handle ::raw? https://vitepress.dev/guide/markdown#raw

image

Already added

@brc-dd
Copy link
Member

brc-dd commented Dec 30, 2024

It's an issue with that component I guess. VitePress' styles are not conflicting.

If you keep v-model:

image

If you remove v-model:

image

If you check src/ui/input/ShadcnInput.vue, the disabled prop there doesn't affect styles. It only adds disabled attribute to input element.

@qianmoQ
Copy link
Author

qianmoQ commented Dec 30, 2024

Open: https://playground.view-shadcn-ui.devlive.org/
Input Code:

<template>
  <ShadcnAlert>
    <p>Welcome to the View Shadcn UI Playground</p>
    <p>欢迎来到 View Shadcn UI 演练场</p>
  </ShadcnAlert>
  <br />
  <ShadcnInput placeholder="Input" v-model="input" disabled />
</template>

<script setup lang="ts">
</script>

The effect can be rendered, but the component effect is lost when used in the vitepress document

@brc-dd brc-dd added bug Something isn't working and removed need more info Further information is requested labels Dec 30, 2024
@brc-dd
Copy link
Member

brc-dd commented Dec 30, 2024

It's because of the reset styles in vitepress. It's adding background-color: transparent to input. includeFiles: [/vp-doc\.css/, /base\.css/] should have worked but is not working in dev for some reason (works fine if you do pnpm docs:build && pnpm docs:serve). I'm taking a look.

@brc-dd
Copy link
Member

brc-dd commented Dec 30, 2024

Re-installing vitepress in your repo seems to work fine. Can you try adding /base\.css/ thing in your postcss config and remove pnpm-lock.yaml and re-run pnpm i && pnpm docs:dev? It most likely was some postcss or vite regression 👀

@brc-dd brc-dd removed the bug Something isn't working label Dec 30, 2024
@qianmoQ
Copy link
Author

qianmoQ commented Dec 30, 2024

After reinstalling, the same problem

@brc-dd
Copy link
Member

brc-dd commented Dec 30, 2024

Did you remove node_modules and pnpm lock? And added base.css to postcss config?

It's appearing like this to me:

image


It's same as what's shown on the playground:

image

@qianmoQ
Copy link
Author

qianmoQ commented Dec 30, 2024

Did you remove node_modules and pnpm lock? And added base.css to postcss config?

It's appearing like this to me:

image It's same as what's shown on the playground: image

How to add base.css and postcss? Where to add them?

@brc-dd
Copy link
Member

brc-dd commented Dec 30, 2024

update docs/postcss.config.mjs file to this in your repo:

import { postcssIsolateStyles } from 'vitepress'

export default {
    plugins: [
        postcssIsolateStyles({
            includeFiles: [/vp-doc\.css/, /base\.css/]
        })
    ]
}

@qianmoQ
Copy link
Author

qianmoQ commented Dec 30, 2024

Please see https://playground.view-shadcn-ui.devlive.org/?codeKey=code-editor-search

Executing Command + F (on mac) in the editor still affects my position style

image

The correct one is

image

@brc-dd
Copy link
Member

brc-dd commented Dec 30, 2024

Position calculation logic in src/ui/code-editor/feature/search.ts seems wrong. It is setting wrong left and top positions on that find element. You'll need to debug that.

@qianmoQ
Copy link
Author

qianmoQ commented Dec 31, 2024

Position calculation logic in src/ui/code-editor/feature/search.ts seems wrong. It is setting wrong left and top positions on that find element. You'll need to debug that.
Sorry, I sent the wrong example. The correct one should be

image

In viewpress

https://view-shadcn-ui.devlive.org/components/view/code-editor.html#context-menu

playground URL : https://playground.view-shadcn-ui.devlive.org/?codeKey=code-editor-context-menu

Use the right mouse button

The position calculated in the code is correct, but it is not displayed

@brc-dd
Copy link
Member

brc-dd commented Dec 31, 2024

top is wrong:

image


If I manually adjust it to smaller value it works fine

image


In src/ui/code-editor/feature/context-menu.ts it should be clientX and clientY instead of pageX and pageY in line 22 and 23. But even then it doesn't set when right clicking for the first time:

Screen.Recording.2024-12-31.at.4.42.12.PM.mp4

@qianmoQ
Copy link
Author

qianmoQ commented Dec 31, 2024

I am confused that the problem only occurs when pageX and pageY are nested in vitepress. There is no such problem when using them separately. I use appendBody. Are there any restrictions on pageX and pageY in vitepress?
The editor needs to get the focus to trigger. The focus was not in the editor for the first time, so it was not triggered.

@brc-dd
Copy link
Member

brc-dd commented Dec 31, 2024

It's not happening on your playground because there is no scrollbar there. clientX/Y and pageX/Y will be same if your page is at it's very top/left. Refer https://stackoverflow.com/a/21452887/11613622 -- it's unrelated to vitepress.

@qianmoQ
Copy link
Author

qianmoQ commented Dec 31, 2024

Thank you so much

@qianmoQ qianmoQ closed this as completed Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants