WPML
ステータス
未解決
報告対象
WPML Multilingual CMS 4.6.11
トピックタグ
Bug

問題の概要

言語スイッチャーGutenbergブロックとそのDropdown clickオプションを使用している場合、ドロップダウン領域の外側をクリックしても期待通りに閉じません。

回避策

先に進む前に、必ずサイトの完全なバックアップを取得してください。


  • …/wp-content/plugins/sitepress-multilingual-cms/classes/block-editor/Blocks/LanguageSwitcher/Render.php ファイルを開きます。

  • 123行目を探します。

  • 以下のコードを:
    				if ( $dpFirstItem ) {
    					$dpFirstItem->setAttribute(
    						'onclick',
    						"(()=>{const ariaExpanded = this.children[0].getAttribute('aria-expanded');
    					this.children[0].setAttribute('aria-expanded', ariaExpanded === 'true' ? 'false' : 'true');})(this);"
    					);
    				}

  • 次のように置き換えます:
    if ($dpFirstItem) {
        $dpFirstItem->setAttribute(
            'onclick',
            "(()=>{
                const ariaExpanded = this.children[0].getAttribute('aria-expanded');
                this.children[0].setAttribute('aria-expanded', ariaExpanded === 'true' ? 'false' : 'true');
                
                if (ariaExpanded !== 'true') {
                    const expandedItem = this;
                    const closeExpandedItem = (event) => {
                        if (!expandedItem.contains(event.target)) {
                            expandedItem.children[0].setAttribute('aria-expanded', 'false');
                            document.removeEventListener('click', closeExpandedItem);
                        }
                    };
                    document.addEventListener('click', closeExpandedItem);
                }
            })(this);"
        );
    }

すべての既知の問題 →