Skip to content

Conversation

@KumJungMin
Copy link
Contributor

@KumJungMin KumJungMin commented May 18, 2024

Defect Fixes


Testing & Resolve method

Issue generation condition

  • Horizontal scrolling occurs at the top-level element.
  • There is a dropdown inside a dialog modal.
  • When opening the modal and trying to select from the dropdown, the horizontal scroll shifts.

How to Issue Generation

  • If you want to reproduce the issue, you can add the following code in the master branch and test it.

assets/styles/layout/_core.scss

// overflow-x: hidden;

pages/sample/index.vue

<template>
    <div>
        <div :style="{ backgroundColor: 'red', width: '200vw', height: '20px' }"></div>
        <Dialog v-model:visible="visible" modal header="My modal" :style="{ width: '50vw' }">
            <Dropdown v-model="selected" :options="items" placeholder="Select an item" />
        </Dialog>
        <Button label="Open Modal" @click="visible = true" />
    </div>
</template>

<script>
import Dropdown from 'primevue/dropdown';
import Dialog from 'primevue/dialog';
import Button from 'primevue/button';
export default {
    setup() {
        definePageMeta({
            layout: ''
        });
    },
    data() {
        return {
            visible: false,
            selected: null,
            items: [
                { label: 'Item 1', value: 'Item 1' },
                { label: 'Item 2', value: 'Item 2' },
                { label: 'Item 3', value: 'Item 3' }
            ]
        };
    },
    components: {
        Dropdown,
        Dialog,
        Button
    }
};
</script>

npm run dev
2024-05-18.8.04.35.mov

How to resolve

  • The reason for the horizontal scrolling is that the logic for moving the horizontal scroll of the dropdown is triggered when trying to select a dropdown item.
  • Therefore, preventing the horizontal scroll movement will stop the issue from occurring.
// before
 element.scrollIntoView && element.scrollIntoView({ block: 'nearest', inline: 'start' }); // cause: "inline: start"
// after
 element.scrollIntoView && element.scrollIntoView({ block: 'nearest' });

@vercel
Copy link

vercel bot commented May 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
primevue ⬜️ Ignored (Inspect) Visit Preview May 18, 2024 10:56am
primevue-v4 ⬜️ Ignored (Inspect) Visit Preview May 18, 2024 10:56am

@KumJungMin KumJungMin marked this pull request as ready for review May 18, 2024 11:11
@KumJungMin KumJungMin changed the title #4488 fix: prevent horizontal scroll, when dropdown item selecting fix(dropdown): prevent horizontal scroll, when dropdown item selecting #4488 May 18, 2024
@KumJungMin KumJungMin changed the title fix(dropdown): prevent horizontal scroll, when dropdown item selecting #4488 fix(Dropdown): prevent horizontal scroll, when dropdown item selecting #4488 Jun 10, 2024
@KumJungMin KumJungMin changed the title fix(Dropdown): prevent horizontal scroll, when dropdown item selecting #4488 fix(Dropdown): prevent horizontal scroll, when dropdown item selecting Jun 10, 2024
@HardWorkerFree
Copy link

It looks like this bug has reappeared in version 4.0.0+

element.scrollIntoView && element.scrollIntoView({ block: 'nearest', inline: 'start' });

The fix (3.53.0) looked like this

element.scrollIntoView && element.scrollIntoView({ block: 'nearest' });

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

Successfully merging this pull request may close these issues.

Dropdown: incorrectly renders when in a modal on top of horizontally scrollable content

3 participants