Skip to content

Commit f73c1bd

Browse files
committed
chore: update from main
2 parents 5b44078 + a46ef1d commit f73c1bd

File tree

5 files changed

+85
-8
lines changed

5 files changed

+85
-8
lines changed

packages/components/src/components/accordion-item/accordion-item.lite.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import {
22
onMount,
3+
onUpdate,
34
Show,
45
Slot,
56
useDefaultProps,
67
useMetadata,
78
useRef,
8-
useStore
9+
useStore,
10+
useTarget
911
} from '@builder.io/mitosis';
1012
import { DBAccordionItemProps, DBAccordionItemState } from './model';
1113
import { cls, getBooleanAsString, uuid } from '../../utils';
@@ -26,6 +28,19 @@ export default function DBAccordionItem(props: DBAccordionItemProps) {
2628
const state = useStore<DBAccordionItemState>({
2729
_id: DEFAULT_ID,
2830
_open: false,
31+
_name: undefined,
32+
initialized: false,
33+
handleNameAttribute: () => {
34+
if (_ref) {
35+
const setAttribute = _ref.setAttribute;
36+
_ref.setAttribute = (attribute: string, value: string) => {
37+
setAttribute.call(_ref, attribute, value);
38+
if (attribute === 'name') {
39+
state._name = value;
40+
}
41+
};
42+
}
43+
},
2944
handleToggle: (event: ClickEvent<HTMLElement> | any) => {
3045
// We need this for react https://github.com/facebook/react/issues/15486#issuecomment-488028431
3146
event?.preventDefault();
@@ -42,14 +57,31 @@ export default function DBAccordionItem(props: DBAccordionItemProps) {
4257
if (props.defaultOpen) {
4358
state._open = props.defaultOpen;
4459
}
60+
61+
state.initialized = true;
4562
});
63+
64+
onUpdate(() => {
65+
if (_ref && state.initialized) {
66+
useTarget({ react: () => state.handleNameAttribute() });
67+
}
68+
}, [_ref, state.initialized]);
69+
70+
onUpdate(() => {
71+
if (props.name) {
72+
state._name = props.name;
73+
}
74+
}, [props.name]);
75+
4676
// jscpd:ignore-end
4777

4878
return (
4979
<li id={state._id} class={cls('db-accordion-item', props.className)}>
5080
<details
5181
aria-disabled={getBooleanAsString(props.disabled)}
5282
ref={_ref}
83+
/* @ts-expect-error This is a new api for details */
84+
name={state._name}
5385
open={state._open}>
5486
<summary onClick={(event) => state.handleToggle(event)}>
5587
<Show when={props.headlinePlain}>

packages/components/src/components/accordion-item/model.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import {
22
GlobalProps,
33
GlobalState,
4+
InitializedState,
5+
NameProps,
6+
NameState,
47
TextProps,
58
ToggleEventProps,
69
ToggleEventState
@@ -27,12 +30,15 @@ export type DBAccordionItemDefaultProps = {
2730

2831
export type DBAccordionItemProps = DBAccordionItemDefaultProps &
2932
GlobalProps &
30-
ToggleEventProps;
33+
ToggleEventProps &
34+
NameProps;
3135

3236
export type DBAccordionItemDefaultState = {
3337
_open?: boolean;
3438
};
3539

3640
export type DBAccordionItemState = DBAccordionItemDefaultState &
3741
GlobalState &
38-
ToggleEventState<HTMLElement>;
42+
ToggleEventState<HTMLElement> &
43+
InitializedState &
44+
NameState;

packages/components/src/components/tab-item/model.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
IconAfterProps,
99
IconProps,
1010
InitializedState,
11+
NameProps,
12+
NameState,
1113
ShowIconProps
1214
} from '../../shared/model';
1315

@@ -38,7 +40,8 @@ export type DBTabItemProps = GlobalProps &
3840
ActiveProps &
3941
AriaControlsProps &
4042
ChangeEventProps<HTMLInputElement> &
41-
ShowIconProps;
43+
ShowIconProps &
44+
NameProps;
4245

4346
export type DBTabItemDefaultState = {
4447
_selected: boolean;
@@ -47,4 +50,5 @@ export type DBTabItemDefaultState = {
4750
export type DBTabItemState = DBTabItemDefaultState &
4851
GlobalState &
4952
ChangeEventState<HTMLInputElement> &
50-
InitializedState;
53+
InitializedState &
54+
NameState;

packages/components/src/components/tab-item/tab-item.lite.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,20 @@ export default function DBTabItem(props: DBTabItemProps) {
2626
const _ref = useRef<HTMLInputElement | any>(null);
2727
// jscpd:ignore-start
2828
const state = useStore<DBTabItemState>({
29-
initialized: false,
3029
_selected: false,
30+
_name: undefined,
31+
initialized: false,
32+
handleNameAttribute: () => {
33+
if (_ref) {
34+
const setAttribute = _ref.setAttribute;
35+
_ref.setAttribute = (attribute: string, value: string) => {
36+
setAttribute.call(_ref, attribute, value);
37+
if (attribute === 'name') {
38+
state._name = value;
39+
}
40+
};
41+
}
42+
},
3143
handleChange: (event: any) => {
3244
if (props.onChange) {
3345
props.onChange(event);
@@ -59,12 +71,22 @@ export default function DBTabItem(props: DBTabItemProps) {
5971
// jscpd:ignore-end
6072

6173
onUpdate(() => {
62-
if (props.active && state.initialized && _ref) {
63-
_ref.click();
74+
if (state.initialized && _ref) {
75+
if (props.active) {
76+
_ref.click();
77+
}
78+
79+
useTarget({ react: () => state.handleNameAttribute() });
6480
state.initialized = false;
6581
}
6682
}, [_ref, state.initialized]);
6783

84+
onUpdate(() => {
85+
if (props.name) {
86+
state._name = props.name;
87+
}
88+
}, [props.name]);
89+
6890
return (
6991
<li class={cls('db-tab-item', props.className)} role="none">
7092
<label
@@ -82,6 +104,7 @@ export default function DBTabItem(props: DBTabItemProps) {
82104
ref={_ref}
83105
type="radio"
84106
role="tab"
107+
name={state._name}
85108
id={props.id}
86109
onInput={(event: any) => state.handleChange(event)}
87110
/>

packages/components/src/shared/model.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ export type PopoverState = {
217217
handleAutoPlacement: () => void;
218218
};
219219

220+
export type NameProps = {
221+
/**
222+
* The name attribute gives the name of the element to group it.
223+
*/
224+
name?: string;
225+
};
226+
227+
export type NameState = {
228+
_name?: string;
229+
handleNameAttribute: () => void;
230+
};
231+
220232
export type ContentSlotProps = {
221233
/**
222234
* Default slot which is used to pass in additional content.

0 commit comments

Comments
 (0)