Skip to content

Commit

Permalink
Simplify keyboard and focus events
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Jul 19, 2023
1 parent f1a5b91 commit 5ba4f72
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 19 deletions.
1 change: 1 addition & 0 deletions src/components/keyboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const Keyboard = ( { activeKeys, keyLayout, onKeyClick }: Props ) => {
{ keys.map( ( key, index ) => (
<button
key={ index }
tabIndex={ -1 }
className={ classnames( 'piano-block-keyboard__key', {
'piano-block-keyboard__key--white': ! key.isBlackKey,
'piano-block-keyboard__key--black': key.isBlackKey,
Expand Down
5 changes: 0 additions & 5 deletions src/components/keyboard/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@
cursor: pointer;
}

&:focus-visible {
outline: var(--wp-admin-theme-color, #007cba) auto 4px;
outline-offset: -2px;
}

&.is-pressed,
&:active {

Expand Down
14 changes: 0 additions & 14 deletions src/components/piano/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,6 @@ const Piano = ( { settings, onChange }: Props ) => {

// Trigger the note corresponding to the pressed key.
const onKeyDown = ( event: KeyboardEvent ): void => {
// Remove focus from key.
const activeElement = ref.current?.ownerDocument.activeElement;
if ( activeElement && activeElement.classList.contains( 'piano-block-keyboard__key' ) ) {
ref.current.focus();
}

// Disable unexpected key events on select elements.
const isAcceptableKey = [ 'ArrowUp', 'ArrowDown', 'Enter', 'Tab' ].includes( event.key );
if ( activeElement && activeElement?.tagName === 'SELECT' && ! isAcceptableKey ) {
event.preventDefault();
}

if ( ! isReady || ! piano ) {
return;
}
Expand Down Expand Up @@ -148,8 +136,6 @@ const Piano = ( { settings, onChange }: Props ) => {

// Stop the note when the key is released.
const onKeyUp = ( event: KeyboardEvent ) => {
event.preventDefault();

if ( ! isReady || ! piano ) {
return;
}
Expand Down

0 comments on commit 5ba4f72

Please sign in to comment.