mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 07:21:17 +08:00
Merge pull request #30276 from msmx-mnakagawa/fix-angular-accent-character-issue
Angular: Fix accent character issue
This commit is contained in:
commit
ed3beb3c25
@ -96,7 +96,9 @@ export abstract class AbstractRenderer {
|
||||
|
||||
const analyzedMetadata = new PropertyExtractor(storyFnAngular.moduleMetadata, component);
|
||||
|
||||
const storyUid = targetDOMNode.getAttribute(STORY_UID_ATTRIBUTE);
|
||||
const storyUid = this.generateStoryUIdFromRawStoryUid(
|
||||
targetDOMNode.getAttribute(STORY_UID_ATTRIBUTE)
|
||||
);
|
||||
const componentSelector = storyUid !== null ? `${targetSelector}[${storyUid}]` : targetSelector;
|
||||
if (storyUid !== null) {
|
||||
const element = targetDOMNode.querySelector(targetSelector);
|
||||
@ -143,6 +145,27 @@ export abstract class AbstractRenderer {
|
||||
return storyIdIsInvalidHtmlTagName ? `sb-${id.replace(invalidHtmlTag, '')}-component` : id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Angular is unable to handle components that have selectors with accented attributes.
|
||||
*
|
||||
* Therefore, stories break when meta's title contains accents.
|
||||
* https://github.com/storybookjs/storybook/issues/29132
|
||||
*
|
||||
* This method filters accents from a given raw id. For example, this method converts
|
||||
* 'Example/Button with an "é" accent' into 'Example/Button with an "e" accent'.
|
||||
*
|
||||
* @memberof AbstractRenderer
|
||||
* @protected
|
||||
*/
|
||||
protected generateStoryUIdFromRawStoryUid(rawStoryUid: string | null) {
|
||||
if (rawStoryUid === null) {
|
||||
return rawStoryUid;
|
||||
}
|
||||
|
||||
const accentCharacters = /[\u0300-\u036f]/g;
|
||||
return rawStoryUid.normalize('NFD').replace(accentCharacters, '');
|
||||
}
|
||||
|
||||
/** Adds DOM element that angular will use as bootstrap component. */
|
||||
protected initAngularRootElement(targetDOMNode: HTMLElement, targetSelector: string) {
|
||||
targetDOMNode.innerHTML = '';
|
||||
|
Loading…
x
Reference in New Issue
Block a user