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

fix: components model bugs #295

Merged
merged 1 commit into from
Aug 21, 2023
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
2 changes: 0 additions & 2 deletions packages/components/popper/src/popperAnchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {
PrimitiveProps,
} from '@oku-ui/primitive'
import type { Measurable } from '@oku-ui/utils'
import { type Scope } from '@oku-ui/provide'
import { Primitive, primitiveProps } from '@oku-ui/primitive'
import { useComposedRefs, useForwardRef } from '@oku-ui/use-composable'
import { usePopperInject } from './popper'
Expand All @@ -24,7 +23,6 @@ export type PopperAnchorElement = HTMLDivElement

interface PopperAnchorProps extends PrimitiveProps {
virtualRef?: Ref<Measurable | null>
scopeCheckbox?: Scope
}

const popperAnchorProps = {
Expand Down
3 changes: 1 addition & 2 deletions packages/components/popper/src/popperArrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
type PrimitiveProps,
primitiveProps,
} from '@oku-ui/primitive'
import { type Scope } from '@oku-ui/provide'
import type { ArrowProps } from '@oku-ui/arrow'
import { OkuArrow } from '@oku-ui/arrow'
import { useForwardRef } from '@oku-ui/use-composable'
Expand All @@ -25,7 +24,7 @@ export type PopperArrowIntrinsicElement = ElementType<'svg'>
export type PopperArrowElement = SVGSVGElement

interface PopperArrowProps extends PrimitiveProps, ArrowProps {
scopePopper?: Scope

}

const popperArrow = defineComponent({
Expand Down
23 changes: 15 additions & 8 deletions packages/components/switch/src/Switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ const switchProps = {
type: String as PropType<'on' | 'off'>,
default: 'on',
},
onCheckedChange: {
type: Function as PropType<(checked: boolean) => void>,
},
}

const [createSwitchProvide, createSwitchScope]
Expand All @@ -93,15 +90,18 @@ const Switch = defineComponent({
...scopeSwitchProps,
...primitiveProps,
},
emits: ['update:modelValue'],
emits: {
'update:modelValue': (checked: boolean) => true,
'checkedChange': (checked: boolean) => true,
'click': (event: MouseEvent) => true,
},
setup(props, { attrs, emit, slots }) {
const {
checked: checkedProp,
defaultChecked,
required,
disabled,
value: switchValue,
onCheckedChange,
name,
} = toRefs(props)

Expand All @@ -112,6 +112,13 @@ const Switch = defineComponent({
const composedRefs = useComposedRefs(buttonRef, forwardedRef)

const modelValue = useModel(props, 'modelValue')
const proxyChecked = computed({
get: () => modelValue.value !== undefined
? modelValue.value
: (checkedProp.value !== undefined ? checkedProp.value : undefined),
set: () => {
},
})

const isFormControl = ref<boolean>(false)

Expand All @@ -125,11 +132,11 @@ const Switch = defineComponent({
})

const { state, updateValue } = useControllable({
prop: computed(() => modelValue.value ?? checkedProp.value),
prop: computed(() => proxyChecked.value),
defaultProp: computed(() => defaultChecked.value),
onChange: (value: boolean) => {
onCheckedChange.value?.(value)
emit('update:modelValue', value)
emit('checkedChange', value)
},
})

Expand All @@ -154,7 +161,7 @@ const Switch = defineComponent({
'ref': composedRefs,
'asChild': props.asChild,
...switchProps,
'onClick': composeEventHandlers(switchProps.onClick, (event) => {
'onClick': composeEventHandlers(props.onClick, (event: MouseEvent) => {
updateValue(!state.value)

if (isFormControl.value) {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/tabs/src/stories/TabsDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ defineProps<ITabsProps>()
}

&[data-state="active"] {
--border-color: #ff0000;
--border-color: #b3cd7c;
}

&:focus {
Expand Down
8 changes: 5 additions & 3 deletions packages/components/tabs/src/tabTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ const tabsTriggerProps = {
type: Boolean as PropType<boolean>,
default: false,
},
onMousedown: Function as PropType<(e: MouseEvent) => void>,
onKeydown: Function as PropType<(e: KeyboardEvent) => void>,
onFocus: Function as PropType<(e: FocusEvent) => void>,
}

const TabTrigger = defineComponent({
Expand All @@ -43,6 +40,11 @@ const TabTrigger = defineComponent({
...scopeTabsProps,
...primitiveProps,
},
emits: {
mousedown: (e: MouseEvent) => true,
keydown: (e: KeyboardEvent) => true,
focus: (e: FocusEvent) => true,
},
setup(props, { slots, attrs }) {
const { scopeOkuTabs, value, disabled } = toRefs(props)
const { ...triggerAttrs } = attrs
Expand Down
23 changes: 13 additions & 10 deletions packages/components/toggle/src/toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ const toggleProps = {
type: Boolean,
default: false,
},
onClick: {
type: Function as PropType<(event: MouseEvent) => void>,
default: undefined,
},
onPressedChange: {
type: Function as PropType<(pressed: boolean) => void>,
default: undefined,
},
}

const Toggle = defineComponent({
Expand All @@ -64,15 +56,26 @@ const Toggle = defineComponent({
...toggleProps,
...primitiveProps,
},
emits: ['update:pressed', 'update:modelValue'],
emits: {
'update:modelValue': (pressed: boolean) => true,
'pressedChange': (pressed: boolean) => true,
'click': (event: MouseEvent) => true,
},
setup(props, { attrs, slots, emit }) {
const { pressed, defaultPressed, disabled } = toRefs(props)
const modelValue = useModel(props, 'modelValue')
const proxyChecked = computed({
get: () => modelValue.value !== undefined
? modelValue.value
: (pressed.value !== undefined ? pressed.value : undefined),
set: () => {
},
})

const forwardedRef = useForwardRef()

const { state, updateValue } = useControllable({
prop: computed(() => modelValue.value ?? pressed.value),
prop: computed(() => proxyChecked.value),
defaultProp: computed(() => defaultPressed.value),
onChange: (pressed) => {
emit('update:modelValue', pressed)
Expand Down
Loading