-
Notifications
You must be signed in to change notification settings - Fork 4.7k
ToggleGroupControl: Document and add disabled prop in types.ts #69715
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
base: trunk
Are you sure you want to change the base?
ToggleGroupControl: Document and add disabled prop in types.ts #69715
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
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.
By the way, there is a way to add custom filter logic to react-docgen-typescript so that any disabled props will always be visible in the Storybook props table (and thus the auto-generated readmes). Do you think that's worth doing?
IIRC, the default logic filters out standard HTML attribute props that don't have explicit descriptions, as well as prop type definitions that originate in node_modules.
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.
We could make exceptions for the most important / impactful attributes such as 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.
I tried to add an exception for the disabled prop when generation the components doc:
Diff
diff --git a/bin/api-docs/gen-components-docs/index.mjs b/bin/api-docs/gen-components-docs/index.mjs
index 30888acf85..5455799771 100644
--- a/bin/api-docs/gen-components-docs/index.mjs
+++ b/bin/api-docs/gen-components-docs/index.mjs
@@ -19,8 +19,14 @@ const MANIFEST_GLOB = 'packages/components/src/**/docs-manifest.json';
const OPTIONS = {
shouldExtractLiteralValuesFromEnum: true,
shouldRemoveUndefinedFromOptional: true,
- propFilter: ( prop ) =>
- prop.parent ? ! /node_modules/.test( prop.parent.fileName ) : true,
+ propFilter: ( prop ) => {
+ if ( prop.name === 'disabled' ) {
+ return true;
+ }
+ return prop.parent
+ ? ! /node_modules/.test( prop.parent.fileName )
+ : true;
+ },
savePropValueAsString: true,
};After that, when I ran npm run docs:components, the documentation for the FormFileUpload component was updated:
Diff
diff --git a/packages/components/src/form-file-upload/README.md b/packages/components/src/form-file-upload/README.md
index 74e6e36938..3ec885b44d 100644
--- a/packages/components/src/form-file-upload/README.md
+++ b/packages/components/src/form-file-upload/README.md
@@ -46,6 +46,11 @@ can be uploaded by the user. e.g: `image/*,video/*`.
Children are passed as children of `Button`.
+### `disabled`
+
+ - Type: `boolean`
+ - Required: No
+
### `icon`
- Type: `IconType`First of all, should we consider automatically generating documentation for the ToggleGroupControl component and its subcomponents?
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.
Hey @t-hamano , Thanks for the detailed explanation.
I have little to no experience working with automated document generation tools. Am I expected to update the PR with the above diffs you pointed out? ie. add disabled as an exception, then run this command npm run docs:components.
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.
Yup, you can look at docs-manifest.json files in the components package and look for related PRs (such as #68209) for inspiration.
Before auto-generating docs, you may have to re-organize the way ToggleGroupControl exports its compound components, from the current way to using Object.assign (see these docs and how Menu and Tabs do it).
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.
We need to add the prop filter logic that @t-hamano demonstrated in the Storybook main.js as well.
For the purposes of this PR, how about we keep the manual README for this component, and deal with auto-generation as a separate task?
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.
I have opened a new PR which focuses on automating the doc in this PR #69970. Please have a look at it and provide me feedback to improve upon it.
For the purpose of this PR. We have the disabled prop added in the README.md, Please let me know if any other change is needed from my end.
|
Hey @t-hamano , Is there any possibility we continue with this PR? on terms shared by @ciampo
Let me know what are your thoughts for the same. I have raised a PR which looks after the auto-generation part #69970 But maybe for the the scope of the current issue we can add it manually? |
What?
Discovered while working on #57862
Related comment: #57862 (comment)
Why?
This PR documents the disabled prop for ToggleGroupControlOption and adds proper TypeScript type definitions for better developer experience.
While PR #63450 added the functionality to disable individual options in ToggleGroupControl, this wasn't documented in the README or demonstrated in Storybook examples. Adding this documentation and proper TypeScript types improves discoverability and makes implementation more consistent with other components in the library.
How?
I worked on the following improvements:
These changes align with how other components like Button, FormToggle, and DropdownOption handle their disabled states.