Skip to content

Commit

Permalink
* core: support to set class name with attr "class".
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Oct 16, 2023
1 parent 7225d08 commit 6f2abd8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/core/src/react/components/h-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class HElement<P extends HElementProps, S = {}> extends Component<P, S> {
}

protected _getProps(props: RenderableProps<P>): Record<string, unknown> {
const {className, attrs, props: componentProps, data, forwardRef, children, component, style, ...others} = props;
const {className, attrs, props: componentProps, data, forwardRef, children, component, style, class: classNameAlt, ...others} = props;
const other = Object.keys(others).reduce<Record<string, unknown>>((map, key) => {

if (key === strDangerouslySetInnerHTML || /^(on[A-Z]|data-|zui-|z-)[a-zA-Z-]+/.test(key)) {
Expand All @@ -48,7 +48,7 @@ export class HElement<P extends HElementProps, S = {}> extends Component<P, S> {
}
return map;
}, {});
return {ref: forwardRef, className: classes(this._getClassName(props)) || undefined, style, [`z-gid-${this._gid}`]: '', ...other, ...attrs, ...componentProps};
return {ref: forwardRef, className: classes(this._getClassName(props), classNameAlt) || undefined, style, [`z-gid-${this._gid}`]: '', ...other, ...attrs, ...componentProps};
}

protected _getComponent(props: RenderableProps<P>): ComponentType | keyof JSX.IntrinsicElements {
Expand Down
6 changes: 6 additions & 0 deletions lib/core/src/react/types/h-element-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export interface HElementProps extends PreactDOMAttributes, Attributes {
*/
className?: ClassNameLike;


/**
* The alternative class name of the element.
*/
class?: ClassNameLike;

/**
* The style of the element.
*/
Expand Down

0 comments on commit 6f2abd8

Please sign in to comment.