The Wayback Machine - https://web.archive.org/web/20201101222352/https://github.com/hperrin/svelte-material-ui/issues/108
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IconButton retains 'focused' class #108

Open
Escalion opened this issue Mar 5, 2020 · 3 comments
Open

IconButton retains 'focused' class #108

Escalion opened this issue Mar 5, 2020 · 3 comments
Assignees

Comments

@Escalion
Copy link
Contributor

@Escalion Escalion commented Mar 5, 2020

IconButton does not 'blur' when it loses focus, retaining it's --background-focused class after the mouse or touch leaves the item.

@Escalion
Copy link
Contributor Author

@Escalion Escalion commented Mar 5, 2020

<script>
  import Menu, {
    SelectionGroup,
    SelectionGroupIcon
  } from '@smui/menu';

  import {
    Anchor
  } from '@smui/menu-surface';

  import List, {
    Item,
    Separator,
    Text,
    PrimaryText,
    SecondaryText,
    Graphic
  } from '@smui/list';

  import IconButton from '@smui/icon-button';

  let menu;
  let anchor;

  export let clicked = 'nada';

  let closeMenu = function (){
    menu.setOpen(false)
  }
</script>
<div use:Anchor bind:this={anchor}>
<IconButton class="material-icons" on:click={()=> menu.setOpen(true)}>menu</IconButton>
<Menu bind:this={menu} anchor={false} bind:anchorElement={anchor} anchorCorner="BOTTOM_LEFT" on:mouseleave={closeMenu} on:focusout={closeMenu}>
  <List>
    <!-- Common menu items here -->
    <Item on:SMUI:action={()=> clicked = 'item'}><Text>Menu Item</Text></Item>
    <Separator />
    <!-- Specific to view menu items here -->
  </List>
</Menu>
</div>

You can see in this example I add handler to close the menu too, but this snippet recreates the issue.

@Escalion
Copy link
Contributor Author

@Escalion Escalion commented Mar 5, 2020

Modifying the IconButton invocation to:
<IconButton class="material-icons" on:mouseleave={blur} on:focusout={blur} on:click={()=> menu.setOpen(true)}>menu</IconButton>
and adding the following function to the script tag:

let blur = function(ev) {
      ev.target.blur()
  }

Gives ALMOST the expected result.
When you defocus by 'clicking away' it seems to work, however when you click the menu item, it's back to square one.

@hperrin
Copy link
Owner

@hperrin hperrin commented Mar 6, 2020

This is an icon button used as a menu? Hmm. I haven’t considered that case before. Let me do some investigation to see what’s going on.

@hperrin hperrin self-assigned this Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.