nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - Select component when clicked scrolls down the page

Open claide opened this issue 10 months ago • 4 comments

NextUI Version

2.2.10

Describe the bug

I installed NextUI on my Next project 14.0.3. I tried to use the Select component and supplied a dynamic values of ages. What happen is when I click on the Select component, the page scrolls down to the level of where the select component is positioned and it changes its value. It always happen only when I supply the ages values to the select component.

I also found out that the Select component only accepts string values which is I convert my ages to string type.

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

This is my age values

import { Option } from '@/types/Option'

export const ageOptions = (): Option<number>[] => {
  return Array.from({ length: 68 }, (_, index) => {
    const value = 18 + index
    return { value, label: `${value}` }
  })
}

Option type

export interface Option<TValue> {
  value: TValue
  label: string
}

Page component

import {
  ageOptions as ageOptionFn,
} from '@/utils/options'

const ageOptions = ageOptionFn()

const ViewTrigger: React.FC<TriggerProps> = ({ triggerData }) => {
  return (
    <>
      // some codes here...
      <Select
        items={ageOptions}
        defaultSelectedKeys={[ageTo.toString()]}
        label="Age To"
        labelPlacement="outside"
        onChange={handleSelect(setAgeTo)}
        selectionMode="single"
        disallowEmptySelection={true}
        className="absolute right-0 w-1/2"
      >
        {(item) => <SelectItem key={item.value}>{item.label}</SelectItem>}
      </Select>
    </>
  )
}

Expected behavior

As a user, I expect to see normal behavior of select box but I am experiencing weird things like scrolling the page down and changing the value when clicking the component.

Screenshots or Videos

No response

Operating System Version

macOS

Browser

Chrome

claide avatar Apr 26 '24 02:04 claide

  1. can you try on the latest version? we've changed quite a lot after 2.2.10.
  2. can you also show a screen record to demonstrate the issue?
  3. a stackblitz link would be nice for us to start debugging on the same ground.

wingkwong avatar Apr 26 '24 03:04 wingkwong

I am experiencing this same issue even after upgrading to 2.3.6

chiester avatar May 07 '24 14:05 chiester

This has to do (for me) with having the Select component set to full width on mobile. If I change "w-full" to, say, "w-5/6", the scroll jump does not happen.

chiester avatar May 07 '24 14:05 chiester

Closing due to no response from OP.

wingkwong avatar May 16 '24 12:05 wingkwong

Sorry for the late update, I believe it's due to how I structure my divs. I tried to put the component inside it's own parent div and the issue disappeared.

claide avatar May 17 '24 07:05 claide

I also have this issue - the Select component jumps when selected on mobile, but setting the width to anything under 90% fixes the behavior

ncullen93 avatar Sep 29 '24 18:09 ncullen93