Skip to content

Instantly share code, notes, and snippets.

@seanCodes
Created April 27, 2021 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanCodes/1a8746cf24418f7ffc5e23373402ef1e to your computer and use it in GitHub Desktop.
Save seanCodes/1a8746cf24418f7ffc5e23373402ef1e to your computer and use it in GitHub Desktop.
Inconsistent sorted list
import { inject as service } from '@ember/service';
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
@service
store;
get sortedTodos() {
return this.model.sortBy('isDone');
}
}
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
export default class TodoModel extends Model {
@attr
text;
@attr('boolean', { defaultValue: false })
isDone;
}
import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
export default class ApplicationRoute extends Route {
@service
store;
model() {
this.store.push({
data: [
{ type: 'todo', id: '1', attributes: { text: 'Todo 1', isDone: false } },
{ type: 'todo', id: '2', attributes: { text: 'Todo 2', isDone: false } },
{ type: 'todo', id: '3', attributes: { text: 'Todo 3', isDone: false } },
],
});
return this.store.peekAll('todo')
}
}
body {
margin: 1em 2em;
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;
}
ul {
list-style-type: none;
}
li {
margin-bottom: 0.5em;
}
input:focus {
outline: 3px solid hsla(210, 100%, 70%, 0.5);
}
<h1>
Inconsistent sorted list behavior
</h1>
<ul>
{{#each this.sortedTodos key="@identity" as |todo|}}
<li>
<label>
<Input @type="checkbox" @checked={{todo.isDone}} />
{{todo.text}}
</label>
</li>
{{/each}}
</ul>
<br>
<p>
Check and uncheck <strong>Todo 2</strong>’s
checkbox and observe how the input outline
<em>persists while unchecking</em> but
<em>does not when checking</em>.
</p>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0",
"ember-data": "3.18.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment