Skip to content

Commit

Permalink
Revert "fix(DropdownMenu): fix recursive update when passing object l…
Browse files Browse the repository at this point in the history
…iteral to title-class (#12614)" (#12617)
  • Loading branch information
inottn committed Feb 4, 2024
1 parent 3d494b8 commit 892d018
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 33 deletions.
12 changes: 4 additions & 8 deletions packages/vant/src/dropdown-menu/DropdownMenu.tsx
Expand Up @@ -2,7 +2,6 @@ import {
ref,
computed,
defineComponent,
toRaw,
type InjectionKey,
type CSSProperties,
type ExtractPropTypes,
Expand All @@ -18,6 +17,7 @@ import {
makeNumericProp,
createNamespace,
HAPTICS_FEEDBACK,
type ComponentInstance,
} from '../utils';

// Composables
Expand All @@ -33,7 +33,6 @@ import {

// Types
import type { DropdownMenuProvide, DropdownMenuDirection } from './types';
import type { DropdownItemInstance } from '../dropdown-item';

const [name, bem] = createNamespace('dropdown-menu');

Expand Down Expand Up @@ -64,10 +63,7 @@ export default defineComponent({
const barRef = ref<HTMLElement>();
const offset = ref(0);

const { children, linkChildren } = useChildren<
DropdownItemInstance,
unknown
>(DROPDOWN_KEY);
const { children, linkChildren } = useChildren(DROPDOWN_KEY);
const scrollParent = useScrollParent(root);

const opened = computed(() =>
Expand Down Expand Up @@ -125,9 +121,9 @@ export default defineComponent({
});
};

const renderTitle = (item: DropdownItemInstance, index: number) => {
const renderTitle = (item: ComponentInstance, index: number) => {
const { showPopup } = item.state;
const { disabled, titleClass } = toRaw(item.$props);
const { disabled, titleClass } = item;

return (
<div
Expand Down
25 changes: 0 additions & 25 deletions packages/vant/src/dropdown-menu/test/index.spec.tsx
Expand Up @@ -367,28 +367,3 @@ test('auto-locate prop', async () => {

vi.doUnmock('../../utils/dom');
});

test('title-class prop', async () => {
const titleClass = ref({ custom: true });
const wrapper = mount({
setup() {
return () => (
<DropdownMenu>
<DropdownItem titleClass={{ custom: true }} />
<DropdownItem titleClass={titleClass.value} />
</DropdownMenu>
);
},
});

await later();

const titles = wrapper.findAll('.van-dropdown-menu__title');
// using object literal should work
expect(titles[0].classes()).toContain('custom');
expect(titles[1].classes()).toContain('custom');

titleClass.value.custom = false;
await later();
expect(titles[1].classes()).not.toContain('custom');
});

0 comments on commit 892d018

Please sign in to comment.