Skip to content

Commit

Permalink
Revert "prepare 1.6.5"
Browse files Browse the repository at this point in the history
This reverts commit c311360.
  • Loading branch information
RobinMalfait committed Jun 20, 2022
1 parent f4d1acb commit bc0b64a
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('Rendering', () => {
})
)

describe.skip('Equality', () => {
describe('Equality', () => {
let options = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
Expand Down
13 changes: 11 additions & 2 deletions packages/@headlessui-react/src/components/combobox/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,11 @@ let ComboboxRoot = forwardRefWithAs(function Combobox<
props: Props<
TTag,
ComboboxRenderPropArg<TType>,
'value' | 'onChange' | 'disabled' | 'name' | 'nullable' | 'multiple'
'value' | 'onChange' | 'disabled' | 'name' | 'nullable' | 'multiple' | 'by'
> & {
value: TType
onChange(value: TType): void
by?: (keyof TType & string) | ((a: TType, z: TType) => boolean)
disabled?: boolean
__demoMode?: boolean
name?: string
Expand All @@ -327,6 +328,7 @@ let ComboboxRoot = forwardRefWithAs(function Combobox<
name,
value,
onChange: theirOnChange,
by = (a, z) => a === z,
disabled = false,
__demoMode = false,
nullable = false,
Expand All @@ -352,7 +354,14 @@ let ComboboxRoot = forwardRefWithAs(function Combobox<
let buttonRef = useRef<_Data['buttonRef']['current']>(null)
let optionsRef = useRef<_Data['optionsRef']['current']>(null)

let compare = useEvent((a, z) => a === z)
let compare = useEvent(
typeof by === 'string'
? (a: TType, z: TType) => {
let property = by as unknown as keyof TType
return a[property] === z[property]
}
: by
)

let isSelected: (value: TType) => boolean = useCallback(
(compareValue) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('Rendering', () => {
})
)

describe.skip('Equality', () => {
describe('Equality', () => {
let options = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
Expand Down
13 changes: 11 additions & 2 deletions packages/@headlessui-react/src/components/listbox/listbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,11 @@ let ListboxRoot = forwardRefWithAs(function Listbox<
props: Props<
TTag,
ListboxRenderPropArg,
'value' | 'onChange' | 'disabled' | 'horizontal' | 'name' | 'multiple'
'value' | 'onChange' | 'disabled' | 'horizontal' | 'name' | 'multiple' | 'by'
> & {
value: TType
onChange(value: TType): void
by?: (keyof TType & string) | ((a: TType, z: TType) => boolean)
disabled?: boolean
horizontal?: boolean
name?: string
Expand All @@ -326,6 +327,7 @@ let ListboxRoot = forwardRefWithAs(function Listbox<
value,
name,
onChange,
by = (a, z) => a === z,
disabled = false,
horizontal = false,
multiple = false,
Expand All @@ -341,7 +343,14 @@ let ListboxRoot = forwardRefWithAs(function Listbox<
value,
onChange,
mode: multiple ? ValueMode.Multi : ValueMode.Single,
compare: useEvent((a, z) => a === z),
compare: useEvent(
typeof by === 'string'
? (a: TType, z: TType) => {
let property = by as unknown as keyof TType
return a[property] === z[property]
}
: by
),
},
},
labelRef: createRef(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ describe('Rendering', () => {
})
)

it.skip(
it(
'should expose internal data as a render prop',
suppressConsoleLogs(async () => {
function Example() {
Expand Down Expand Up @@ -372,7 +372,7 @@ describe('Rendering', () => {
})
)

describe.skip('Equality', () => {
describe('Equality', () => {
let options = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,25 @@ let RadioGroupRoot = forwardRefWithAs(function RadioGroup<
props: Props<
TTag,
RadioGroupRenderPropArg,
RadioGroupPropsWeControl | 'value' | 'onChange' | 'disabled' | 'name'
RadioGroupPropsWeControl | 'value' | 'onChange' | 'disabled' | 'name' | 'by'
> & {
value: TType
onChange(value: TType): void
by?: (keyof TType & string) | ((a: TType, z: TType) => boolean)
disabled?: boolean
name?: string
},
ref: Ref<HTMLElement>
) {
let { value, name, onChange, disabled = false, ...theirProps } = props
let compare = useEvent((a, z) => a === z)
let { value, name, onChange, by = (a, z) => a === z, disabled = false, ...theirProps } = props
let compare = useEvent(
typeof by === 'string'
? (a: TType, z: TType) => {
let property = by as unknown as keyof TType
return a[property] === z[property]
}
: by
)
let [state, dispatch] = useReducer(stateReducer, { options: [] } as StateDefinition<TType>)
let options = state.options as unknown as Option<TType>[]
let [labelledby, LabelProvider] = useLabels()
Expand Down
28 changes: 14 additions & 14 deletions packages/@headlessui-react/src/utils/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@ function _render<TTag extends ElementType, TSlot>(
}

let dataAttributes: Record<string, string> = {}
// if (slot) {
// let exposeState = false
// let states = []
// for (let [k, v] of Object.entries(slot)) {
// if (typeof v === 'boolean') {
// exposeState = true
// }
// if (v === true) {
// states.push(k)
// }
// }
//
// if (exposeState) dataAttributes[`data-headlessui-state`] = states.join(' ')
// }
if (slot) {
let exposeState = false
let states = []
for (let [k, v] of Object.entries(slot)) {
if (typeof v === 'boolean') {
exposeState = true
}
if (v === true) {
states.push(k)
}
}

if (exposeState) dataAttributes[`data-headlessui-state`] = states.join(' ')
}

if (Component === Fragment) {
if (Object.keys(compact(rest)).length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ describe('Rendering', () => {
})
)

describe.skip('Equality', () => {
describe('Equality', () => {
let options = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
Expand Down
11 changes: 10 additions & 1 deletion packages/@headlessui-vue/src/components/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import { useOutsideClick } from '../../hooks/use-outside-click'
import { Hidden, Features as HiddenFeatures } from '../../internal/hidden'
import { objectToFormEntries } from '../../utils/form'

function defaultComparator<T>(a: T, z: T): boolean {
return a === z
}

enum ComboboxStates {
Open,
Closed,
Expand Down Expand Up @@ -112,6 +116,7 @@ export let Combobox = defineComponent({
props: {
as: { type: [Object, String], default: 'template' },
disabled: { type: [Boolean], default: false },
by: { type: [String, Function], default: () => defaultComparator },
modelValue: { type: [Object, String, Number, Boolean] },
name: { type: String },
nullable: { type: Boolean, default: false },
Expand Down Expand Up @@ -175,7 +180,11 @@ export let Combobox = defineComponent({
value,
mode,
compare(a: any, z: any) {
return a === z
if (typeof props.by === 'string') {
let property = props.by as unknown as any
return a[property] === z[property]
}
return props.by(a, z)
},
nullable,
inputRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('Rendering', () => {
})
)

describe.skip('Equality', () => {
describe('Equality', () => {
let options = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
Expand Down
11 changes: 10 additions & 1 deletion packages/@headlessui-vue/src/components/listbox/listbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import { useOutsideClick } from '../../hooks/use-outside-click'
import { Hidden, Features as HiddenFeatures } from '../../internal/hidden'
import { objectToFormEntries } from '../../utils/form'

function defaultComparator<T>(a: T, z: T): boolean {
return a === z
}

enum ListboxStates {
Open,
Closed,
Expand Down Expand Up @@ -112,6 +116,7 @@ export let Listbox = defineComponent({
props: {
as: { type: [Object, String], default: 'template' },
disabled: { type: [Boolean], default: false },
by: { type: [String, Function], default: () => defaultComparator },
horizontal: { type: [Boolean], default: false },
modelValue: { type: [Object, String, Number, Boolean] },
name: { type: String, optional: true },
Expand Down Expand Up @@ -167,7 +172,11 @@ export let Listbox = defineComponent({
value,
mode,
compare(a: any, z: any) {
return a === z
if (typeof props.by === 'string') {
let property = props.by as unknown as any
return a[property] === z[property]
}
return props.by(a, z)
},
orientation: computed(() => (props.horizontal ? 'horizontal' : 'vertical')),
labelRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ describe('Rendering', () => {
assertActiveElement(getByText('Option 3'))
})

describe.skip('Equality', () => {
describe('Equality', () => {
let options = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import { Hidden, Features as HiddenFeatures } from '../../internal/hidden'
import { attemptSubmit, objectToFormEntries } from '../../utils/form'
import { getOwnerDocument } from '../../utils/owner'

function defaultComparator<T>(a: T, z: T): boolean {
return a === z
}

interface Option {
id: string
element: Ref<HTMLElement | null>
Expand Down Expand Up @@ -71,6 +75,7 @@ export let RadioGroup = defineComponent({
props: {
as: { type: [Object, String], default: 'div' },
disabled: { type: [Boolean], default: false },
by: { type: [String, Function], default: () => defaultComparator },
modelValue: { type: [Object, String, Number, Boolean] },
name: { type: String, optional: true },
},
Expand Down Expand Up @@ -102,7 +107,11 @@ export let RadioGroup = defineComponent({
)
),
compare(a: any, z: any) {
return a === z
if (typeof props.by === 'string') {
let property = props.by as unknown as any
return a[property] === z[property]
}
return props.by(a, z)
},
change(nextValue: unknown) {
if (props.disabled) return false
Expand Down
28 changes: 14 additions & 14 deletions packages/@headlessui-vue/src/utils/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,20 @@ function _render({
let children = slots.default?.(slot)

let dataAttributes: Record<string, string> = {}
// if (slot) {
// let exposeState = false
// let states = []
// for (let [k, v] of Object.entries(slot)) {
// if (typeof v === 'boolean') {
// exposeState = true
// }
// if (v === true) {
// states.push(k)
// }
// }
//
// if (exposeState) dataAttributes[`data-headlessui-state`] = states.join(' ')
// }
if (slot) {
let exposeState = false
let states = []
for (let [k, v] of Object.entries(slot)) {
if (typeof v === 'boolean') {
exposeState = true
}
if (v === true) {
states.push(k)
}
}

if (exposeState) dataAttributes[`data-headlessui-state`] = states.join(' ')
}

if (as === 'template') {
children = flattenFragments(children as VNode[])
Expand Down

0 comments on commit bc0b64a

Please sign in to comment.