Skip to content

Conversation

@Qs-F
Copy link
Contributor

@Qs-F Qs-F commented Oct 22, 2025

関連URL

https://smarthr.atlassian.net/browse/SHRUI-1330

概要

ModelessDialogのtitleが意図せずstringのみを許容する様になっていたのを修正

変更内容

  • BaseのPropsとの交差型の適用によりtitleがstring & ReactNode ~> stringになっていた
  • これをPropsWithHTMLAttributes型を導入し、HTMLElement経由のpropsをOmitするようにしたことで解決
  • 以降、HTMLElementの型をベースにする場合はPropsWithHTMLAttributesを使用することを推奨したい

確認方法

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 22, 2025

Open in StackBlitz

npm i https://pkg.pr.new/kufu/smarthr-ui@5907

commit: 8a505c9

> = ({
type ComponentProps = PropsWithHTMLAttributes<
Props & VariantProps<typeof classNameGenerator>,
'div'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

もともとはBaseElementProps (HTMLDivElementのAttributesからBaseのPropsをOmitしたもの) を設定していたが、

  • 本来はidとariaがほしいくらいですべてのHTMLの属性が欲しいわけではないはず
    • 欲しいものだけを絞るべき
    • 絞る対応はまた別で行っていくので、一回単純化しておく
  • BaseElementPropsをここで使う理由がない

ため、'div' を直接使用しています。

@Qs-F Qs-F marked this pull request as ready for review October 22, 2025 12:00
@Qs-F Qs-F requested a review from a team as a code owner October 22, 2025 12:00
@Qs-F Qs-F requested review from masa0527 and uknmr and removed request for a team October 22, 2025 12:00

export type PropsWithHTMLAttributes<
Props extends Parameters<FC>[0],
E extends ElementType,
Copy link
Contributor Author

@Qs-F Qs-F Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いい感じの被らない型パラメーター名が思いつかなかったので…

export type ElementRefProps<T extends ElementType> = { ref?: ElementRef<T> }

export type PropsWithHTMLAttributes<
Props extends Parameters<FC>[0],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters<FC>[0] が効いてなさそうに見えました。

Suggested change
Props extends Parameters<FC>[0],
Props,

export const ModelessDialog: FC<
Props & BaseElementProps & VariantProps<typeof classNameGenerator>
> = ({
type ComponentProps = PropsWithHTMLAttributes<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React の ComponentProps と見間違うかも。FC<> に直接書いちゃうか ModelessDialogProps とするかかと思いました。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reactのComponentProps型はrefを受け取れるかどうか明確ではないため事故の原因になりやすく、慣習的に基本的に使わないべきはずです!あとここはrefを受け取ることが明確ではないため、やるならModelessDialogPropsWithoutRefになりますが、ほかのコンポーネントでも同様の書き方のパターンが出てくるのでComponentPropsが1番良いのではと思っての判断でした

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

他コンポーネントは Props を FC に渡してることが一番多い気がします。
ModelessDialog の Props の名前を変えて、ここを Props とする手もありそうです。
React の ComponentProps 型を使わないのはわかるけど、FC<ComponentProps> だけ見るとうーんってなりました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants