Code Monkey home page Code Monkey logo

Comments (3)

yong-asial avatar yong-asial commented on May 25, 2024

@madcoda9000 This could be done with manipulating DOM element in Javascript. There are many ways to achieve it. here is one way - https://codepen.io/yong-asial/pen/GRXYYvX

HTML

<ons-page id="expanding">
<ons-list>
 <ons-list-item expandable id="list1">
          <label id="label1">Tap to expand 1</label>
          <div class="expandable-content" id="content1">Expandable content 1</div>
        </ons-list-item>
        <ons-list-item expandable id="list2">
          <label id="label2">Tap to expand 2</label>
          <div class="expandable-content" id="content2">Expandable content 2</div>
        </ons-list-item>
        <ons-list-item expandable id="list3">
          <label id="label3">Tap to expand 3</label>
          <div class="expandable-content" id="content3">Expandable content 3</div>
        </ons-list-item>
</ons-list>
</ons-page>

JS

// label - to trigger click event
const label1 = document.getElementById('label1');
const label2 = document.getElementById('label2');
const label3 = document.getElementById('label3');

// list - to listen for click event
const list1 = document.getElementById('list1');
const list2 = document.getElementById('list2');
const list3 = document.getElementById('list3');

const isVisible = (element) => {
  return (window.getComputedStyle(element).display !== 'none' && window.getComputedStyle(element).visibility !== 'hidden');
};


const collapseOther = (id) => {
  [1, 2, 3].forEach(item => {
    if (id !== item) {
      const content = document.getElementById('content' + item);
      if (isVisible(content)) {
        const label = document.getElementById('label' + item);
        label.click();
      }
    }
  });

};

const handleListClicked = (event) => {
  const labelElement = event.target.children[0] || event.target;
  if (labelElement == label1) {
    collapseOther(1);
  } else if (labelElement == label2) {
    collapseOther(2);
  } else if (labelElement == label3) {
    collapseOther(3); 
  }
};

[list1, list2, list3].forEach((li) => li.addEventListener('click', handleListClicked));

from onsenui.

github-actions avatar github-actions commented on May 25, 2024

This issue is stale because it has been open for 60 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

from onsenui.

github-actions avatar github-actions commented on May 25, 2024

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

from onsenui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.