-
Notifications
You must be signed in to change notification settings - Fork 141
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
chore: CheckBoxの内部処理を最適化する #5340
base: master
Are you sure you want to change the base?
Conversation
95b4662
to
d9400a9
Compare
commit: |
@@ -59,48 +57,29 @@ const checkbox = tv({ | |||
'shr-relative shr-box-border shr-inline-block shr-h-[theme(fontSize.base)] shr-w-[theme(fontSize.base)] shr-shrink-0 shr-translate-y-[0.125em] shr-leading-none', | |||
label: [ | |||
'smarthr-ui-CheckBox-label shr-ms-0.5 shr-cursor-pointer shr-text-base shr-leading-tight', | |||
'[[data-disabled=true]>&]:shr-pointer-events-none [[data-disabled=true]>&]:shr-cursor-not-allowed [[data-disabled=true]>&]:shr-text-disabled', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
動的にclassを変更するのではなく、親要素の data-disabled
を確認、それに応じてstyleを変更するようにしました。
これにより、memo化の効率が良くなります
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: data-disabled
より has-[input:disabled]
のほうがsmarthr-ui内ではよく使われているかなと思ったんですが、data属性の方を選んだ理由ってありますか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const AriaHiddenBox = React.memo<{ className: string }>(({ className }) => ( | ||
<span className={className} aria-hidden="true" /> | ||
)) | ||
|
||
const CheckIconArea = React.memo<Pick<Props, 'mixed'> & { className: string; iconStyle: string }>( | ||
({ mixed, className, iconStyle }) => ( | ||
<span className={className}> | ||
{mixed ? <FaMinusIcon className={iconStyle} /> : <FaCheckIcon className={iconStyle} />} | ||
</span> | ||
), | ||
) | ||
|
||
const LabeledChildren = React.memo<PropsWithChildren<{ className: string; htmlFor: string }>>( | ||
({ children, htmlFor, className }) => | ||
children && ( | ||
<label htmlFor={htmlFor} className={className}> | ||
{children} | ||
</label> | ||
), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これらの箇所はほぼ書き換わる可能性がないため、memo化しています。
LabeledChildrenはこのコンポーネント自体のchildrenを受け取っていますが、CheckBoxの特性上、ReactNodeでわたってくる可能性はひくく、ほとんどがstringとなるため、効率は良いはずです
関連URL
概要
変更内容
確認方法