🐛 [#1121] focus-trap in Header and Search #466
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue: https://taiga.maykinmedia.nl/project/open-inwoner/issue/1121
Problem: propagation (bubbling) of events from the mobile menu into the dialog element that catches focus away from everything else.
Notes for learning:
Ways to inspect the constructor in file "open_inwoner/js/components/abstract/component.js":
constructor(node, initialState = {}) { console.log('Component constructor', node, initialState) [.....]
and
setState(changes) { console.log('setState', changes) [.....]
Ways to inspect the clickEvents in inspector: by using 'matches' in these 5 console-logs in file "open_inwoner/js/components/header/header.js":
bindEvents() { this.node.addEventListener('keyup', this.onKeyUp.bind(this)) this.node.addEventListener('click', (e) => { console.log('click in bindEvents') if ( e.target.matches('.header__button') || e.target.matches('.header__button *') ) { this.setState({ open: !this.state.open }) } }) }
2 & 3.
getButton() { console.log('getButton') return BEM.getChildBEMNode(this.node, BLOCK_HEADER, ELEMENT_BUTTON) } getSubMenu() { console.log('getSubMenu') return BEM.getChildBEMNode(this.node, BLOCK_HEADER, ELEMENT_SUBMENU) }
render(state) { console.log('render', state) document.body.classList.add('body') BEM.toggleModifier(document.body, MODIFIER_OPEN, state.open) BEM.toggleModifier(this.getButton(), MODIFIER_OPEN, state.open) if (matchMedia('(max-width: 767px)').matches) { state.open ? this.getSubMenu().show() : this.getSubMenu().close() } if (state.open) { window.scrollTo({ x: 0, y: 0 }) } }