Skip to content

Commit

Permalink
fix(types): ensure toggleClass's second arg is optional (#8829)
Browse files Browse the repository at this point in the history
## Description
Generated types are mangled for `Component.toggleClass()`, because tsc
doesn't understand `~` namespaces. The second arg is then not marked as
optional.

## Specific Changes proposed
Refactor JSDoc

## Requirements Checklist
- [x] Feature implemented / Bug fixed
- [ ] If necessary, more likely in a feature request than a bug fix
- [ ] Change has been verified in an actual browser (Chrome, Firefox,
IE)
  - [ ] Unit Tests updated or fixed
  - [ ] Docs/guides updated
- [ ] Example created ([starter template on
JSBin](https://codepen.io/gkatsev/pen/GwZegv?editors=1000#0))
- [x] Has no DOM changes which impact accessiblilty or trigger warnings
(e.g. Chrome issues tab)
  - [x] Has no changes to JSDoc which cause `npm run docs:api` to error
- [ ] Reviewed by Two Core Contributors
  • Loading branch information
mister-ben authored Aug 14, 2024
1 parent e715145 commit 65f8546
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -983,10 +983,10 @@ class Component {
* - `classToToggle` gets removed when {@link Component#hasClass} would return true.
*
* @param {string} classToToggle
* The class to add or remove based on (@link Component#hasClass}
* The class to add or remove. Passed to DOMTokenList's toggle()
*
* @param {boolean|Dom~predicate} [predicate]
* An {@link Dom~predicate} function or a boolean
* @param {boolean|Dom.PredicateCallback} [predicate]
* A boolean or function that returns a boolean. Passed to DOMTokenList's toggle().
*/
toggleClass(classToToggle, predicate) {
Dom.toggleClass(this.el_, classToToggle, predicate);
Expand Down
9 changes: 5 additions & 4 deletions src/js/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export function removeClass(element, ...classesToRemove) {
/**
* The callback definition for toggleClass.
*
* @callback module:dom~PredicateCallback
* @callback PredicateCallback
* @param {Element} element
* The DOM element of the Component.
*
Expand All @@ -271,8 +271,9 @@ export function removeClass(element, ...classesToRemove) {
*
* @return {boolean|undefined}
* If `true` is returned, the `classToToggle` will be added to the
* `element`. If `false`, the `classToToggle` will be removed from
* the `element`. If `undefined`, the callback will be ignored.
* `element`, but not removed. If `false`, the `classToToggle` will be removed from
* the `element`, but not added. If `undefined`, the callback will be ignored.
*
*/

/**
Expand All @@ -285,7 +286,7 @@ export function removeClass(element, ...classesToRemove) {
* @param {string} classToToggle
* The class that should be toggled.
*
* @param {boolean|module:dom~PredicateCallback} [predicate]
* @param {boolean|PredicateCallback} [predicate]
* See the return value for {@link module:dom~PredicateCallback}
*
* @return {Element}
Expand Down

0 comments on commit 65f8546

Please sign in to comment.