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

chore: master merge feature #6582

Merged
merged 3 commits into from
Mar 28, 2024
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
7 changes: 7 additions & 0 deletions src/components/picker-view/tests/picker-view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ describe('PickerView', () => {
const wheelEl = document.body.querySelectorAll(
`.${classPrefix}-column-wheel`
)[0]

const itemList = document.body.querySelectorAll(
`.${classPrefix}-column-item`
)

fireEvent.mouseDown(wheelEl, {
clientY: 0,
buttons: 1,
Expand All @@ -99,6 +104,8 @@ describe('PickerView', () => {
})
fireEvent.mouseUp(wheelEl)
expect(wheelEl).toHaveStyle('transform: translateY(-68px)')
// 滚到了第3个item
expect(itemList[2]).toHaveClass(`${classPrefix}-column-item-active`)
fireEvent.click(screen.getByText('change'))
await waitFor(() => expect(wheelEl).toHaveStyle('transform: none'))
})
Expand Down
9 changes: 7 additions & 2 deletions src/components/picker-view/wheel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import isEqual from 'lodash/isEqual'
import { useIsomorphicLayoutEffect } from 'ahooks'
import { measureCSSLength } from '../../utils/measure-css-length'
import { supportsPassive } from '../../utils/supports-passive'
import classNames from 'classnames'

const classPrefix = `adm-picker-view`

Expand Down Expand Up @@ -271,15 +272,19 @@ export const Wheel = memo<Props>(
{column.map((item, index) => {
const selected = props.value === item.value
if (selected) selectedIndex = index

function handleClick() {
draggingRef.current = false
scrollSelect(index)
}

return (
<div
key={item.key ?? item.value}
data-selected={item.value === value}
className={`${classPrefix}-column-item`}
data-selected={selected}
className={classNames(`${classPrefix}-column-item`, {
[`${classPrefix}-column-item-active`]: selected,
})}
onClick={handleClick}
aria-hidden={!selected}
aria-label={selected ? 'active' : ''}
Expand Down
Loading